• postpostscript avatar
    sqliteBuilder
    @postpostscript
    sqliteBuilder: Opinionated safe(r) query builder using tagged templates import { Statement } from "https://esm.town/v/postpostscript/sqliteBuilder"; const unsafeId = "1234 or TRUE" console.log(Statement` SELECT * FROM table WHERE id = ${unsafeId} ${Statement`AND otherCondition`} `) // StatementInstance { // sql: "\nSELECT *\nFROM table\nWHERE id = ?\nAND otherCondition\n", // args: [ "1234 or TRUE" ], // log: false // } const results = await Statement`SELECT ...`.execute() // [ { key: "value", anotherKey: "anotherValue" }, ... ] Or you can pass it directly to @std/sqlite.execute : import { sqlite } from "https://esm.town/v/std/sqlite" await sqlite.execute(Statement`Select ...`) You can combine multiple statements using Statement.prototype.combineWith : Statement`...`.combineWith(Statement`...`, " AND ") [ Statement`fieldA`, Statement`fieldB`, Statement`fieldC`, ].reduce((a, b) => a.combineWith(b, ", "))
    Script
  • nbbaier avatar
    sqliteDump
    @nbbaier
    SQLite Dump Util A utility function that generates SQL statements to dump the data and schema of tables in a SQLite database. Usage This example specifically dumps the users table and logs the output: import { sqliteDump } from "https://esm.town/v/nbbaier/sqliteDump"; const dump = await sqliteDump(["users"]); console.log(dump) You can optionally specify a callback to handle the result. The example below dumps the users table and emails it using std/email . import { email } from "https://esm.town/v/std/email"; import { sqliteDump } from "https://esm.town/v/nbbaier/sqliteDump"; await sqliteDump(["users"], async (res) => { await email({ text: res }); }); Function Signature function sqliteDump(tables?: string[], callback?: ((result: string) => string | void | Promise<void>) | undefined): Promise<string | void> Parameters tables : (Optional) Array of table names to include in the dump. If not provided, all tables will be included. callback : (Optional) An (potentially async) callback function to process the dump result. The callback receives the dump string as its argument.
    Script
  • std avatar
    sqlite
    @std
    SQLite - Docs ↗ SQLite is a lightweight, standard database. Every Val Town account comes with its own private SQLite database that is accessible from any of your vals via std/sqlite . Val Town SQLite is powered by Turso . Usage Migrations ORMs You may find these admin viewers helpful managing your database: SQLite Explorer (built in Val Town) LibSQL Studio Limits You can store 10mb on the free plan and up to 1gb on the paid plan. Contact us if you need more space. 📝 Edit docs
    Script
1
Next
April 24, 2024