Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export function transpileSql(content: string, {id, display}: Record<string, stri
return id === undefined
? display === "false"
? `${sql};`
: `display(Inputs.table(await ${sql}));`
: `display(Inputs.table(await ${sql}, {select: false}));`
: display === "false"
? `const ${id} = await ${sql};`
: `const ${id} = ((_) => (display(Inputs.table(_)), _))(await ${sql});`;
: `const ${id} = ((_) => (display(Inputs.table(_, {select: false})), _))(await ${sql});`;
}

function isValidBinding(input: string): boolean {
Expand Down
12 changes: 6 additions & 6 deletions test/sql-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {transpileSql} from "../src/sql.js";

describe("transpileSql(content, attributes)", () => {
it("compiles a sql expression", () => {
assert.strictEqual(transpileSql("SELECT 1 + 2"), "display(Inputs.table(await sql`SELECT 1 + 2`));");
assert.strictEqual(transpileSql("SELECT 1 + 2"), "display(Inputs.table(await sql`SELECT 1 + 2`, {select: false}));"); // prettier-ignore
});
it("compiles a sql expression with id", () => {
assert.strictEqual(transpileSql("SELECT 1 + 2", {id: "foo"}), "const foo = await sql`SELECT 1 + 2`;");
Expand All @@ -22,13 +22,13 @@ describe("transpileSql(content, attributes)", () => {
assert.throws(() => transpileSql("SELECT 1 + 2", {id: "([foo])"}), /invalid binding/);
});
it("compiles a sql expression with id and display", () => {
assert.strictEqual(transpileSql("SELECT 1 + 2", {id: "foo", display: ""}), "const foo = ((_) => (display(Inputs.table(_)), _))(await sql`SELECT 1 + 2`);"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {id: "foo", display: ""}), "const foo = ((_) => (display(Inputs.table(_, {select: false})), _))(await sql`SELECT 1 + 2`);"); // prettier-ignore
});
it("ignores display if display is implicit", () => {
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: ""}), "display(Inputs.table(await sql`SELECT 1 + 2`));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "t"}), "display(Inputs.table(await sql`SELECT 1 + 2`));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "f"}), "display(Inputs.table(await sql`SELECT 1 + 2`));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "true"}), "display(Inputs.table(await sql`SELECT 1 + 2`));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: ""}), "display(Inputs.table(await sql`SELECT 1 + 2`, {select: false}));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "t"}), "display(Inputs.table(await sql`SELECT 1 + 2`, {select: false}));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "f"}), "display(Inputs.table(await sql`SELECT 1 + 2`, {select: false}));"); // prettier-ignore
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "true"}), "display(Inputs.table(await sql`SELECT 1 + 2`, {select: false}));"); // prettier-ignore
});
it("compiles a sql expression with display=false", () => {
assert.strictEqual(transpileSql("SELECT 1 + 2", {display: "false"}), "sql`SELECT 1 + 2`;");
Expand Down