From 7a6008d0757a4c0052eeecb8fccfed307e561b09 Mon Sep 17 00:00:00 2001 From: Jason Shin Date: Sat, 26 Aug 2023 23:45:08 +1000 Subject: [PATCH] chore: adding statement tests --- .../typescript/statement/function.queries.ts | 31 ++++++++++++++ tests/demo/typescript/statement/function.ts | 10 +++++ tests/demo/typescript/statement/if.queries.ts | 31 ++++++++++++++ tests/demo/typescript/statement/if.ts | 11 +++++ .../typescript/statement/switch.queries.ts | 31 ++++++++++++++ tests/demo/typescript/statement/switch.ts | 10 +++++ tests/demo/typescript/ts-syntax.ts | 42 ------------------- 7 files changed, 124 insertions(+), 42 deletions(-) create mode 100644 tests/demo/typescript/statement/function.queries.ts create mode 100644 tests/demo/typescript/statement/function.ts create mode 100644 tests/demo/typescript/statement/if.queries.ts create mode 100644 tests/demo/typescript/statement/if.ts create mode 100644 tests/demo/typescript/statement/switch.queries.ts create mode 100644 tests/demo/typescript/statement/switch.ts diff --git a/tests/demo/typescript/statement/function.queries.ts b/tests/demo/typescript/statement/function.queries.ts new file mode 100644 index 00000000..d685aa59 --- /dev/null +++ b/tests/demo/typescript/statement/function.queries.ts @@ -0,0 +1,31 @@ + + +export type FunctionAssignParams = []; + + +export interface IFunctionAssignResult { + id: number; +}; + + +export interface IFunctionAssignQuery { + params: FunctionAssignParams; + result: IFunctionAssignResult; +}; + + + + +export type ReturnQueryParams = []; + + +export interface IReturnQueryResult { + id: number; +}; + + +export interface IReturnQueryQuery { + params: ReturnQueryParams; + result: IReturnQueryResult; +}; + diff --git a/tests/demo/typescript/statement/function.ts b/tests/demo/typescript/statement/function.ts new file mode 100644 index 00000000..89339949 --- /dev/null +++ b/tests/demo/typescript/statement/function.ts @@ -0,0 +1,10 @@ +import { sql } from 'sqlx-ts' + +function test() { + const functionAssign = sql`SELECT id FROM items` + + return sql` + -- @name: return query + SELECT id FROM items + `; +} diff --git a/tests/demo/typescript/statement/if.queries.ts b/tests/demo/typescript/statement/if.queries.ts new file mode 100644 index 00000000..edb64d69 --- /dev/null +++ b/tests/demo/typescript/statement/if.queries.ts @@ -0,0 +1,31 @@ + + +export type IfstmtParams = []; + + +export interface IIfstmtResult { + id: number; +}; + + +export interface IIfstmtQuery { + params: IfstmtParams; + result: IIfstmtResult; +}; + + + + +export type NestedIfStmtParams = []; + + +export interface INestedIfStmtResult { + id: number; +}; + + +export interface INestedIfStmtQuery { + params: NestedIfStmtParams; + result: INestedIfStmtResult; +}; + diff --git a/tests/demo/typescript/statement/if.ts b/tests/demo/typescript/statement/if.ts new file mode 100644 index 00000000..b8129767 --- /dev/null +++ b/tests/demo/typescript/statement/if.ts @@ -0,0 +1,11 @@ +import { sql } from 'sqlx-ts' + +if (true) { + const ifstmt = sql`SELECT id FROM items;`; +} + +function testIfStatement() { + if (true) { + const nestedIfStmt = sql`SELECT id FROM items;`; + } +} diff --git a/tests/demo/typescript/statement/switch.queries.ts b/tests/demo/typescript/statement/switch.queries.ts new file mode 100644 index 00000000..bbbc1fc0 --- /dev/null +++ b/tests/demo/typescript/statement/switch.queries.ts @@ -0,0 +1,31 @@ + + +export type Case1Params = []; + + +export interface ICase1Result { + id: number; +}; + + +export interface ICase1Query { + params: Case1Params; + result: ICase1Result; +}; + + + + +export type Case2Params = []; + + +export interface ICase2Result { + id: number; +}; + + +export interface ICase2Query { + params: Case2Params; + result: ICase2Result; +}; + diff --git a/tests/demo/typescript/statement/switch.ts b/tests/demo/typescript/statement/switch.ts new file mode 100644 index 00000000..7060519e --- /dev/null +++ b/tests/demo/typescript/statement/switch.ts @@ -0,0 +1,10 @@ +import { sql } from 'sqlx-ts' + + +switch (true) { + case true: + const case1 = sql`SELECT id FROM items`; + break; + default: + const case2 = sql`SELECT id FROM items`; +} diff --git a/tests/demo/typescript/ts-syntax.ts b/tests/demo/typescript/ts-syntax.ts index 12cd7daf..5ebd7675 100644 --- a/tests/demo/typescript/ts-syntax.ts +++ b/tests/demo/typescript/ts-syntax.ts @@ -17,51 +17,9 @@ SELECT * FROM items // expressions // ///////////////// -const query0 = sql` -SELECT id, points -FROM items; -`; - -const queryCompount = sql` -SELECT items.id, tables.id -FROM items -JOIN tables ON items.table_id = tables.id; -`; - -const query1 = sql`SELECT * FROM items;`; -// variable de -const query2 = sql` - SELECT * FROM items; -`; - -/////////////// -// functions // -/////////////// -function test() { - const query3 = sql` - SELECT * FROM items; - `; - - return sql` - -- @name: testQuery - INSERT INTO - items (food_type, time_takes_to_cook, table_id, points) - VALUES ('steak', 1, 1, 20); - `; -} - /////////////////// // If statements // /////////////////// -if (true) { - const query3 = sql`SELECT * FROM items;`; -} - -function testIfStatement() { - if (true) { - const query3 = sql`SELECT * FROM items;`; - } -} ////////////////////// // Switch Statement //