ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
168 stars 53 forks source link

Allow splicing template insertions `${...x}` #923

Open niveathika opened 3 years ago

niveathika commented 3 years ago

Description: As of now, the raw template supports the 1:1 mapping of parameters to the variable. i.e

// usage
int[] arr = [10, 20];
RawTemplate template = `Test ${arr} type`;

//Desugurs
RawTemplate template = {
    strings: ["Test", " type" ],
    insertions: [[10, 20]]
};

The use case is to support 1:n mapping of the variable in case the variable consists of multiple elements like an array with a default divisor, for instance

// usage
int[] arr = [10, 20];
RawTemplate template = `Test ${arr...} type`;

//Desugurs
RawTemplate template = {
    strings: ["Test", ",", " type" ],
    insertions: [10, 20]
};

The use case comes through SQL to support IN operations such as, "SELECT * FROM testdb WHERE id IN(1,2,3);"

int[] ids = [1, 2, 3]

sql:ParameterizedQuery query = `SELECT * FROM testdb WHERE id IN(${ids})`;
jclark commented 3 years ago

Interesting idea. ${...arr} would be the consistent syntax for this.