Skip to content

Instantly share code, notes, and snippets.

@reidev275
Created February 25, 2020 18:30
Show Gist options
  • Save reidev275/4b0541d17b2c1fccfdd87099766e5e79 to your computer and use it in GitHub Desktop.
Save reidev275/4b0541d17b2c1fccfdd87099766e5e79 to your computer and use it in GitHub Desktop.
const interpretToSql = <A>(dsl: Filter<A>): string => {
switch (dsl.kind) {
case "Equals":
return `[${dsl.field}] = '${dsl.val}'`;
case "Greater":
return `[${dsl.field}] > '${dsl.val}'`;
case "Less":
return `[${dsl.field}] < '${dsl.val}'`;
case "And":
return `(${interpretToSql(dsl.a)} and ${interpretToSql(dsl.b)})`;
case "Or":
return `(${interpretToSql(dsl.a)} or ${interpretToSql(dsl.b)})`;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment