Waddler
Waddler - is a thin SQL client wrapper with modern API inspired by postgresjs and based on ES6 Tagged Template Strings.
You don’t need to learn an api for db clients; just use the
sqltemplate tag for everything
Waddler is our vision of a modern, all-in-one client for any database dialect. It doesn’t perform any specific mappings to or from a database, doesn’t handle complex query building, and doesn’t parse queries. Waddler simply unifies communication with your database using any client you choose - whether it’s a simple TCP connection or an HTTP-based DB client.
We support all the dialects and drivers that Drizzle supports
You can check a full list of clients you can use - here
import { waddler } from "waddler/...";
const sql = waddler({ dbUrl: process.env.DATABASE_URL });
await sql`select 1`;Waddler API consists of sql template, sql.identifier, sql.values and sql.raw operators:
SQL template protects you from SQL injections:
await sql`select * from users where id = ${10}`;select * from users where id = $1;
-- 10 will be passed as a param [10]SQL identifier lets you conveniently provide schema, table and column names to the query. Those will be automatically properly escaped:
await sql`select * from ${sql.identifier("users")}`;
await sql`select * from ${sql.identifier({ schema: "public", table: "users" })}`;
const userIdColumn = sql.identifier({ schema: "public", table: "users", column: "id", as: "userId"});
await sql`select ${userIdColumn} from "users"`;select * from "users";
select * from "public"."users";
select * from "public"."users"."id" as "userId" from "users";SQL values API is designed to help you with insert statements:
const tuples = [["Dan", 27], ["Oleksii", 25]];
await sql`insert into "users" ("name", "age") values ${sql.values(tuples)}`;insert into "users" ("name", "age") values ('Dan', 27), ('Oleksii', 25);SQL raw lets you dynamically build SQL by embedding raw strings:
const listUsers = async (filter: string | undefined) => {
const whereClause = filter ? sql.raw(` where ${filter}`) : sql.raw("");
return sql`select * from "users"${whereClause}`;
}
await listUsers(`"id" = 10`);
await listUsers(`"name" = 'Dan'`);
await listUsers();select * from "users" where "id" = 10;
select * from "users" where "name" = 'Dan';
select * from "users";