-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from hasura/lyndon/pg-bug-report-sooraj
Updating TS target to 2022 to fix pg dependency bug
- Loading branch information
Showing
4 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,14 @@ This changelog documents the changes between release versions. | |
|
||
Changes to be included in the next upcoming releaase. | ||
|
||
## v0.15 | ||
|
||
Updating TypeScript target version from ES2017 to ES2022. | ||
|
||
PR: https://github.com/hasura/ndc-typescript-deno/pull/73 | ||
|
||
* Resolves issues with some dependencies such as deno.land/x/[email protected] | ||
|
||
## v0.14.1 | ||
|
||
Diff: b1bdc55..17e85d5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { Client } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const dbConfig = { | ||
user: "aaysha", | ||
hostname: "asdfasdfasd.us-west-2.aws.neon.tech", | ||
port: 5432, | ||
password: "asdfasdasdf", | ||
database: "asdfasdfasdf", | ||
ssl: true, | ||
sslmode: "require", | ||
}; | ||
|
||
export async function insert_user( | ||
user_name: string, | ||
): Promise< | ||
{ id: string; name: string; created_at: string } | { message: string } | { | ||
error: string; | ||
} | {} | ||
> { | ||
const client = new Client(dbConfig); | ||
|
||
try { | ||
await client.connect(); | ||
|
||
const result = await client.queryObject({ | ||
text: `INSERT INTO users(name) VALUES ('${user_name}') RETURNING *`, | ||
}); | ||
|
||
if (result && result.rows.length > 0 && result.rows[0]) { | ||
return result.rows[0]; | ||
} else { | ||
return { message: "Insert Failed" }; | ||
} | ||
} catch (error) { | ||
console.error("Error:", error); | ||
return { error: "Error: " + error.message }; | ||
} finally { | ||
await client.end(); | ||
} | ||
} | ||
|
||
export async function insert_todos( | ||
user_id: string, | ||
todo: string | ||
): Promise< | ||
{ id: string; user_id: string; todo: string; created_at: string } | { message: string } | { | ||
error: string; | ||
} | {} | ||
> { | ||
const client = new Client(dbConfig); | ||
|
||
try { | ||
await client.connect(); | ||
|
||
|
||
// Check if the user exists in the users table | ||
|
||
const userExistsQuery = await client.queryObject({ | ||
text: `SELECT id FROM users where id =${user_id}` | ||
}) | ||
|
||
if (userExistsQuery.rows.length === 0) { | ||
return { message: "User not found. Insert Failed" }; | ||
} | ||
const result = await client.queryObject({ | ||
text: `INSERT INTO todos(user_id,todo) VALUES ('${user_id}','${todo}') RETURNING *`, | ||
}); | ||
|
||
if (result && result.rows.length > 0 && result.rows[0]) { | ||
return result.rows[0]; | ||
} else { | ||
return { message: "Insert Failed" }; | ||
} | ||
} catch (error) { | ||
console.error("Error:", error); | ||
return { error: "Error: " + error.message }; | ||
} finally { | ||
await client.end(); | ||
} | ||
} | ||
|
||
|
||
export async function delete_todos( | ||
todo_id: string | ||
){ | ||
const client = new Client(dbConfig); | ||
try{ | ||
await client.connect(); | ||
|
||
const result = await client.queryObject({ text: `DELETE FROM todos WHERE id =${todo_id}`}) | ||
if(result.rowCount===1){ | ||
return `Deleted todo with id= ${todo_id} sucesssfully` | ||
}else{ | ||
return "Deletion unsucessfull" | ||
} | ||
}catch(error){ | ||
return "Error : "+ error.message | ||
}finally{ | ||
client.end(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
|
||
import * as test from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | ||
import * as infer from '../infer.ts'; | ||
|
||
// NOTE: It would be good to have explicit timeout for this | ||
// See: https://github.com/denoland/deno/issues/11133 | ||
// Test bug: https://github.com/hasura/ndc-typescript-deno/issues/45 | ||
Deno.test("Inferred Dependency Based Result Type", () => { | ||
const program_path = path.fromFileUrl(import.meta.resolve('./data/pg_dep.ts')); | ||
const vendor_path = path.fromFileUrl(import.meta.resolve('./vendor')); | ||
const program_results = infer.programInfo(program_path, vendor_path, true); | ||
|
||
test.assertEquals(program_results, { | ||
positions: { | ||
delete_todos: [ | ||
"todo_id", | ||
], | ||
insert_todos: [ | ||
"user_id", | ||
"todo", | ||
], | ||
insert_user: [ | ||
"user_name", | ||
], | ||
}, | ||
schema: { | ||
collections: [], | ||
functions: [], | ||
procedures: [ | ||
{ | ||
arguments: { | ||
user_name: { | ||
type: { | ||
name: "String", | ||
type: "named", | ||
}, | ||
}, | ||
}, | ||
name: "insert_user", | ||
result_type: { | ||
name: "insert_user_output", | ||
type: "named", | ||
}, | ||
}, | ||
{ | ||
arguments: { | ||
todo: { | ||
type: { | ||
name: "String", | ||
type: "named", | ||
}, | ||
}, | ||
user_id: { | ||
type: { | ||
name: "String", | ||
type: "named", | ||
}, | ||
}, | ||
}, | ||
name: "insert_todos", | ||
result_type: { | ||
name: "insert_todos_output", | ||
type: "named", | ||
}, | ||
}, | ||
{ | ||
arguments: { | ||
todo_id: { | ||
type: { | ||
name: "String", | ||
type: "named", | ||
}, | ||
}, | ||
}, | ||
name: "delete_todos", | ||
result_type: { | ||
name: "String", | ||
type: "named", | ||
}, | ||
}, | ||
], | ||
scalar_types: { | ||
String: { | ||
aggregate_functions: {}, | ||
comparison_operators: {}, | ||
update_operators: {}, | ||
}, | ||
insert_todos_output: { | ||
aggregate_functions: {}, | ||
comparison_operators: {}, | ||
update_operators: {}, | ||
}, | ||
insert_user_output: { | ||
aggregate_functions: {}, | ||
comparison_operators: {}, | ||
update_operators: {}, | ||
}, | ||
}, | ||
object_types: {}, | ||
} | ||
}); | ||
}); |