Skip to main content

durcno@1.0.0-alpha.30

Minor Changes​

  • c71f751 - Thanks to @almahdi404 !

    feat(connectors): support prepared statements to postgres connector

    Add support for executing queries as prepared statements in the postgres (postgres.js) connector.

    Prepared Statements in Postgres Connector​

    The postgres connector now passes { prepare: true } to postgres.js during query execution when the prepare flag is enabled:

    import { database, defineConfig, eq, prepare } from "durcno";
    import { postgres } from "durcno/connectors/postgres";

    export const db = database(
    schema,
    defineConfig({
    schema: "./schema.ts",
    connector: postgres({
    dbCredentials: { url: process.env.DATABASE_URL! },
    }),
    }),
    );

    const findUser = prepare({ id: Users.id.arg() }, (args) =>
    db
    .prepare()
    .from(Users)
    .select("*")
    .where(() => eq(Users.id, args.id)));

    const users = await findUser.run(db, { id: 1 });

Patch Changes​

  • 54c3a09 - Thanks to @almahdi404 !

    fix(db): make db.raw() rowsHandler argument optional

    db.raw() required a rowsHandler callback positionally, even though passing undefined was already handled at runtime and the documentation listed the argument as optional. This made the common case — executing a raw query and getting the rows back — impossible to express without a redundant identity handler.

    // Before: had to pass a pass-through handler
    const rows = await db.raw<{ id: bigint; }[]>(
    "SELECT id FROM users",
    [],
    (rows) => rows,
    );

    // After: rowsHandler is optional
    const rows = await db.raw<{ id: bigint; }[]>("SELECT id FROM users");

    This is a non-breaking change; existing three-argument calls behave exactly as before.