From c249827b23511854c1a024a967cb1e308fa413b3 Mon Sep 17 00:00:00 2001 From: David Blythe <49919035+writeDavid@users.noreply.github.com> Date: Sun, 16 Jul 2023 13:06:32 -0700 Subject: [PATCH] Update index.ts --- plugins/sql/guest-js/index.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/plugins/sql/guest-js/index.ts b/plugins/sql/guest-js/index.ts index c9824f7c..918bc4e4 100644 --- a/plugins/sql/guest-js/index.ts +++ b/plugins/sql/guest-js/index.ts @@ -76,10 +76,29 @@ export default class Database { * * @example * ```ts + * // for sqlite & postgres + * // INSERT example + * const result = await db.execute( + * "INSERT into todos (id, title, status) VALUES ($1, $2, $3)", + * [ todos.id, todos.title, todos.status ] + * ); + * // UPDATE example * const result = await db.execute( * "UPDATE todos SET title = $1, completed = $2 WHERE id = $3", * [ todos.title, todos.status, todos.id ] * ); + * + * // for mysql + * // INSERT example + * const result = await db.execute( + * "INSERT into todos (id, title, status) VALUES (?, ?, ?)", + * [ todos.id, todos.title, todos.status ] + * ); + * // UPDATE example + * const result = await db.execute( + * "UPDATE todos SET title = ?, completed = ? WHERE id = ?", + * [ todos.title, todos.status, todos.id ] + * ); * ``` */ async execute(query: string, bindValues?: unknown[]): Promise { @@ -91,13 +110,11 @@ export default class Database { values: bindValues ?? [], }, ); - return { lastInsertId, rowsAffected, }; } - /** * **select** * @@ -105,9 +122,15 @@ export default class Database { * * @example * ```ts + * // for sqlite & postgres * const result = await db.select( * "SELECT * from todos WHERE id = $1", id * ); + * + * // for mysql + * const result = await db.select( + * "SELECT * from todos WHERE id = ?", id + * ); * ``` */ async select(query: string, bindValues?: unknown[]): Promise {