### Waddler ClickHouse Get Started Source: https://waddler.drizzle.team/docs/sqlite/get-started Guides for getting started with Waddler and ClickHouse. ```typescript import { drizzle } from 'drizzle-orm/clickhouse-core'; import { sql } from 'drizzle-orm'; // Example for connecting to a ClickHouse database // const db = drizzle(clickhouseConnection); // Example of using sql template // const result = await db.execute(sql`SELECT * FROM users`); ``` -------------------------------- ### Waddler Gel Get Started Source: https://waddler.drizzle.team/docs/sqlite/get-started Guides for getting started with Waddler and Gel. ```typescript import { drizzle } from 'drizzle-orm/gel-core'; import { sql } from 'drizzle-orm'; // Example for connecting to a Gel database // const db = drizzle(gelConnection); // Example of using sql template // const result = await db.execute(sql`SELECT * FROM users`); ``` -------------------------------- ### Waddler MySQL Get Started Source: https://waddler.drizzle.team/docs/sqlite/get-started Guides for getting started with Waddler and MySQL, including PlanetScale, TiDB, and SingleStore. ```typescript import { drizzle } from 'drizzle-orm/mysql-core'; import { sql } from 'drizzle-orm'; // Example for connecting to a MySQL database // const db = drizzle(mysqlConnection); // Example of using sql template // const result = await db.execute(sql`SELECT * FROM users`); ``` -------------------------------- ### Waddler DuckDB Get Started Source: https://waddler.drizzle.team/docs/sqlite/get-started Guides for getting started with Waddler and DuckDB, including DuckDB-neo. ```typescript import { drizzle } from 'drizzle-orm/duckdb-core'; import { sql } from 'drizzle-orm'; // Example for connecting to a DuckDB database // const db = drizzle(duckdbConnection); // Example of using sql template // const result = await db.execute(sql`SELECT * FROM users`); ``` -------------------------------- ### Waddler SQLite Get Started Source: https://waddler.drizzle.team/docs/sqlite/get-started Guides for getting started with Waddler and SQLite, including native SQLite, Expo SQLite, and OP SQLite. ```typescript import { drizzle } from 'drizzle-orm/sqlite-core'; import { sql } from 'drizzle-orm'; // Example for connecting to a SQLite database // const db = drizzle(sqliteConnection); // Example of using sql template // const result = await db.execute(sql`SELECT * FROM users`); ``` -------------------------------- ### Install Waddler and ClickHouse Client Source: https://waddler.drizzle.team/docs/clickhouse/get-started/clickhouse-new Installs the necessary Waddler and ClickHouse client packages along with dotenv and tsx for project setup. Supports npm, yarn, pnpm, and bun package managers. ```npm npm i waddler @clickhouse/client dotenv npm i -D tsx ``` ```yarn yarn add waddler @clickhouse/client dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler @clickhouse/client dotenv pnpm add -D tsx ``` ```bun bun add waddler @clickhouse/client dotenv bun add -D tsx ``` -------------------------------- ### Waddler PostgreSQL Get Started Source: https://waddler.drizzle.team/docs/sqlite/get-started Guides for getting started with Waddler and PostgreSQL, including PlanetScale Postgres, Neon, Vercel Postgres, Supabase, Xata, PGLite, Nile, and Bun SQL. ```typescript import { drizzle } from 'drizzle-orm/pg-core'; import { sql } from 'drizzle-orm'; // Example for connecting to a PostgreSQL database // const db = drizzle(pgConnection); // Example of using sql template // const result = await db.execute(sql`SELECT * FROM users`); ``` -------------------------------- ### Install node-postgres with Waddler (bun) Source: https://waddler.drizzle.team/docs/get-started/postgresql-new Installs the necessary Waddler and node-postgres packages using bun, along with development dependencies. ```bash bun add waddler pg dotenv bun add -D tsx @types/pg ``` -------------------------------- ### Install Expo SQLite Package Source: https://waddler.drizzle.team/docs/sqlite/get-started/expo-new Commands to install the `expo-sqlite` package using npm, yarn, pnpm, or bun. ```bash npx expo install expo-sqlite ``` ```bash yarn expo install expo-sqlite ``` ```bash pnpm expo install expo-sqlite ``` ```bash bun expo install expo-sqlite ``` -------------------------------- ### Install node-postgres with Waddler (npm) Source: https://waddler.drizzle.team/docs/get-started/postgresql-new Installs the necessary Waddler and node-postgres packages using npm, along with development dependencies. ```bash npm i waddler pg dotenv npm i -D tsx @types/pg ``` -------------------------------- ### Install Waddler Package Source: https://waddler.drizzle.team/docs/sqlite/get-started/expo-new Commands to install the `waddler` package using npm, yarn, pnpm, or bun. ```bash npm i waddler ``` ```bash yarn add waddler ``` ```bash pnpm add waddler ``` ```bash bun add waddler ``` -------------------------------- ### Install node-postgres with Waddler (pnpm) Source: https://waddler.drizzle.team/docs/get-started/postgresql-new Installs the necessary Waddler and node-postgres packages using pnpm, along with development dependencies. ```bash pnpm add waddler pg dotenv pnpm add -D tsx @types/pg ``` -------------------------------- ### Install node-postgres with Waddler (yarn) Source: https://waddler.drizzle.team/docs/get-started/postgresql-new Installs the necessary Waddler and node-postgres packages using yarn, along with development dependencies. ```bash yarn add waddler pg dotenv yarn add -D tsx @types/pg ``` -------------------------------- ### Install Waddler and @types/bun with bun Source: https://waddler.drizzle.team/docs/get-started/bun-sql-new Installs the Waddler package and its TypeScript types for Bun using bun. ```bash bun add waddler bun add -D @types/bun ``` -------------------------------- ### Install Waddler and Turso Packages (bun) Source: https://waddler.drizzle.team/docs/sqlite/get-started/turso-new Installs the necessary Waddler and Turso client packages, along with dotenv for environment variables and tsx for running TypeScript files, using bun. ```bash bun add waddler @libsql/client dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and MySQL2 Packages Source: https://waddler.drizzle.team/docs/mysql/get-started/mysql-new Installs the Waddler library, the mysql2 driver, dotenv for environment variables, and tsx for running TypeScript files using npm, yarn, pnpm, or bun. ```npm npm i waddler mysql2 dotenv npm i -D tsx ``` ```yarn yarn add waddler mysql2 dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler mysql2 dotenv pnpm add -D tsx ``` ```bun bun add waddler mysql2 dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and Turso Packages (npm) Source: https://waddler.drizzle.team/docs/sqlite/get-started/turso-new Installs the necessary Waddler and Turso client packages, along with dotenv for environment variables and tsx for running TypeScript files, using npm. ```bash npm i waddler @libsql/client dotenv npm i -D tsx ``` -------------------------------- ### Install Waddler and @types/bun with yarn Source: https://waddler.drizzle.team/docs/get-started/bun-sql-new Installs the Waddler package and its TypeScript types for Bun using yarn. ```bash yarn add waddler yarn add -D @types/bun ``` -------------------------------- ### Install Waddler and Wrangler Packages Source: https://waddler.drizzle.team/docs/sqlite/get-started/do-new Installs the Waddler library and necessary Cloudflare development tools. Supports npm, yarn, pnpm, and bun package managers. ```npm npm i waddler dotenv npm i -D wrangler @cloudflare/workers-types ``` ```yarn yarn add waddler dotenv yarn add -D wrangler @cloudflare/workers-types ``` ```pnpm pnpm add waddler dotenv pnpm add -D wrangler @cloudflare/workers-types ``` ```bun bun add waddler dotenv bun add -D wrangler @cloudflare/workers-types ``` -------------------------------- ### Install Waddler and Dependencies (bun) Source: https://waddler.drizzle.team/docs/get-started/supabase-new Installs the necessary Waddler package, postgres driver, dotenv for environment variables, and tsx for TypeScript execution using bun. ```bash bun add waddler postgres dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and OP-SQLite Packages Source: https://waddler.drizzle.team/docs/sqlite/get-started/op-sqlite-new Commands to install the necessary Waddler and OP-SQLite libraries into your project. These packages provide the core functionality for database interaction. ```bash npm i waddler @op-engineering/op-sqlite ``` ```bash yarn add waddler @op-engineering/op-sqlite ``` ```bash pnpm add waddler @op-engineering/op-sqlite ``` ```bash bun add waddler @op-engineering/op-sqlite ``` -------------------------------- ### Install Waddler and @types/bun with npm Source: https://waddler.drizzle.team/docs/get-started/bun-sql-new Installs the Waddler package and its TypeScript types for Bun using npm. ```bash npm i waddler npm i -D @types/bun ``` -------------------------------- ### Install Waddler and @types/bun with bun Source: https://waddler.drizzle.team/docs/sqlite/get-started/bun-sqlite-new Installs the Waddler package and its TypeScript types for Bun using bun. ```bash bun add waddler bun add -D @types/bun ``` -------------------------------- ### Install Waddler and Neon Serverless Dependencies Source: https://waddler.drizzle.team/docs/get-started/neon-new Installs the necessary Waddler and Neon serverless packages, along with dotenv for environment variables and tsx for running TypeScript files. ```bash npm i waddler @neondatabase/serverless dotenv npm i -D tsx ``` ```bash yarn add waddler @neondatabase/serverless dotenv yarn add -D tsx ``` ```bash pnpm add waddler @neondatabase/serverless dotenv pnpm add -D tsx ``` ```bash bun add waddler @neondatabase/serverless dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and @types/bun with pnpm Source: https://waddler.drizzle.team/docs/get-started/bun-sql-new Installs the Waddler package and its TypeScript types for Bun using pnpm. ```bash pnpm add waddler pnpm add -D @types/bun ``` -------------------------------- ### Install Waddler and PostgreSQL Dependencies Source: https://waddler.drizzle.team/docs/get-started/nile-new Installs the necessary Waddler and PostgreSQL packages along with development dependencies like tsx and @types/pg using various package managers. ```npm npm i waddler pg dotenv npm i -D tsx @types/pg ``` ```yarn yarn add waddler pg dotenv yarn add -D tsx @types/pg ``` ```pnpm pnpm add waddler pg dotenv pnpm add -D tsx @types/pg ``` ```bun bun add waddler pg dotenv bun add -D tsx @types/pg ``` -------------------------------- ### Example DB_FILE_NAME for Testing Source: https://waddler.drizzle.team/docs/sqlite/get-started/bun-sqlite-new Provides an example of setting DB_FILE_NAME in the .env file to create an SQLite database file in the project root for testing purposes. ```dotenv DB_FILE_NAME=mydb.sqlite ``` -------------------------------- ### Install Waddler and Dependencies (npm) Source: https://waddler.drizzle.team/docs/get-started/supabase-new Installs the necessary Waddler package, postgres driver, dotenv for environment variables, and tsx for TypeScript execution using npm. ```bash npm i waddler postgres dotenv npm i -D tsx ``` -------------------------------- ### Install Waddler and Turso Packages (yarn) Source: https://waddler.drizzle.team/docs/sqlite/get-started/turso-new Installs the necessary Waddler and Turso client packages, along with dotenv for environment variables and tsx for running TypeScript files, using yarn. ```bash yarn add waddler @libsql/client dotenv yarn add -D tsx ``` -------------------------------- ### Install Waddler and postgres Packages Source: https://waddler.drizzle.team/docs/connect-planetscale-postgres Provides commands for installing the necessary Waddler and postgres packages using different package managers: npm, yarn, pnpm, and bun. ```bash npm i waddler postgres ``` ```bash yarn add waddler postgres ``` ```bash pnpm add waddler postgres ``` ```bash bun add waddler postgres ``` -------------------------------- ### Install Waddler and Turso Packages (pnpm) Source: https://waddler.drizzle.team/docs/sqlite/get-started/turso-new Installs the necessary Waddler and Turso client packages, along with dotenv for environment variables and tsx for running TypeScript files, using pnpm. ```bash pnpm add waddler @libsql/client dotenv pnpm add -D tsx ``` -------------------------------- ### Install Waddler and Dependencies (pnpm) Source: https://waddler.drizzle.team/docs/get-started/supabase-new Installs the necessary Waddler package, postgres driver, dotenv for environment variables, and tsx for TypeScript execution using pnpm. ```bash pnpm add waddler postgres dotenv pnpm add -D tsx ``` -------------------------------- ### Install Waddler and Dependencies (yarn) Source: https://waddler.drizzle.team/docs/get-started/supabase-new Installs the necessary Waddler package, postgres driver, dotenv for environment variables, and tsx for TypeScript execution using yarn. ```bash yarn add waddler postgres dotenv yarn add -D tsx ``` -------------------------------- ### Install Waddler and TiDB Packages (bun) Source: https://waddler.drizzle.team/docs/mysql/get-started/tidb-new Installs the necessary Waddler and TiDB serverless packages, along with dotenv for environment variables and tsx for running TypeScript files, using bun. ```bash bun add waddler @tidbcloud/serverless dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and TiDB Packages (npm) Source: https://waddler.drizzle.team/docs/mysql/get-started/tidb-new Installs the necessary Waddler and TiDB serverless packages, along with dotenv for environment variables and tsx for running TypeScript files, using npm. ```bash npm i waddler @tidbcloud/serverless dotenv npm i -D tsx ``` -------------------------------- ### Install Waddler and Node-Postgres Packages Source: https://waddler.drizzle.team/docs/get-started/planetscale-postgres-new Installs the necessary Waddler and node-postgres packages along with development dependencies like tsx and @types/pg using different package managers. ```bash npm i waddler pg dotenv npm i -D tsx @types/pg ``` ```bash yarn add waddler pg dotenv yarn add -D tsx @types/pg ``` ```bash pnpm add waddler pg dotenv pnpm add -D tsx @types/pg ``` ```bash bun add waddler pg dotenv bun add -D tsx @types/pg ``` -------------------------------- ### Install Waddler and PlanetScale Dependencies Source: https://waddler.drizzle.team/docs/mysql/get-started/planetscale-new Installs the necessary Waddler and PlanetScale packages for Node.js projects using npm, yarn, pnpm, or bun. Also installs `dotenv` for environment variable management and `tsx` for running TypeScript files. ```npm npm i waddler @planetscale/database dotenv npm i -D tsx ``` ```yarn yarn add waddler @planetscale/database dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler @planetscale/database dotenv pnpm add -D tsx ``` ```bun bun add waddler @planetscale/database dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and LibSQL Client Source: https://waddler.drizzle.team/docs/sqlite/get-started/sqlite-new Installs the Waddler library, the LibSQL client for SQLite, and the tsx package for running TypeScript files. Supports npm, yarn, pnpm, and bun package managers. ```npm npm i waddler @libsql/client dotenv npm i -D tsx ``` ```yarn yarn add waddler @libsql/client dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler @libsql/client dotenv pnpm add -D tsx ``` ```bun bun add waddler @libsql/client dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and TiDB Packages (yarn) Source: https://waddler.drizzle.team/docs/mysql/get-started/tidb-new Installs the necessary Waddler and TiDB serverless packages, along with dotenv for environment variables and tsx for running TypeScript files, using yarn. ```bash yarn add waddler @tidbcloud/serverless dotenv yarn add -D tsx ``` -------------------------------- ### Install Waddler and TiDB Packages (pnpm) Source: https://waddler.drizzle.team/docs/mysql/get-started/tidb-new Installs the necessary Waddler and TiDB serverless packages, along with dotenv for environment variables and tsx for running TypeScript files, using pnpm. ```bash pnpm add waddler @tidbcloud/serverless dotenv pnpm add -D tsx ``` -------------------------------- ### Streaming Users with Waddler Neon Serverless Source: https://waddler.drizzle.team/docs/get-started/neon-new This TypeScript example demonstrates streaming user data from a database using Waddler with Neon Serverless and the pg-query-stream extension. It connects to the database, sets up the stream, iterates through the results, and closes the connection. ```typescript import 'dotenv/config'; import { Client } from '@neondatabase/serverless'; import { waddler } from 'waddler/neon-serverless'; import { queryStream } from 'waddler/extensions/pg-query-stream'; async function main() { const client = new Client(process.env.DATABASE_URL!); await client.connect(); const sql = waddler({ client, extensions: [queryStream()] }); const stream = sql`select * from users;`.stream(); console.log('Streaming users one at a time from the database.') for await (const user of stream) { console.log(user) /* const user: { id: number; name: string; age: number; email: string; } */ } await client.end(); } main(); ``` -------------------------------- ### Setup Database URL Source: https://waddler.drizzle.team/docs/get-started/supabase-new Defines the DATABASE_URL environment variable in the .env file for connecting to the Supabase database. ```dotenv DATABASE_URL= ``` -------------------------------- ### Install Waddler and Xata Client Packages Source: https://waddler.drizzle.team/docs/get-started/xata-new Installs the necessary Waddler and Xata client packages along with dotenv for environment variables, and tsx for running TypeScript files. Supports npm, yarn, pnpm, and bun. ```npm npm i waddler @xata.io/client dotenv npm i -D tsx ``` ```yarn yarn add waddler @xata.io/client dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler @xata.io/client dotenv pnpm add -D tsx ``` ```bun bun add waddler @xata.io/client dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and @types/bun with pnpm Source: https://waddler.drizzle.team/docs/sqlite/get-started/bun-sqlite-new Installs the Waddler package and its TypeScript types for Bun using pnpm. ```bash pnpm add waddler pnpm add -D @types/bun ``` -------------------------------- ### Install Waddler and @types/bun with npm Source: https://waddler.drizzle.team/docs/sqlite/get-started/bun-sqlite-new Installs the Waddler package and its TypeScript types for Bun using npm. ```bash npm i waddler npm i -D @types/bun ``` -------------------------------- ### Install Waddler and @types/bun with yarn Source: https://waddler.drizzle.team/docs/sqlite/get-started/bun-sqlite-new Installs the Waddler package and its TypeScript types for Bun using yarn. ```bash yarn add waddler yarn add -D @types/bun ``` -------------------------------- ### Basic Project File Structure Source: https://waddler.drizzle.team/docs/get-started/vercel-new Illustrates the fundamental file and directory layout for a Waddler project utilizing Vercel Postgres. ```bash 📦 ├ 📂 src │ └ 📜 index.ts ├ 📜 .env ├ 📜 package.json └ 📜 tsconfig.json ``` -------------------------------- ### Project File Structure Source: https://waddler.drizzle.team/docs/sqlite/get-started/bun-sqlite-new Illustrates the basic file structure for a Waddler project using Bun:SQLite, including source files, environment configuration, package management, and TypeScript configuration. ```tree 📦 ├ 📂 src │ └ 📜 index.ts ├ 📜 .env ├ 📜 package.json └ 📜 tsconfig.json ``` -------------------------------- ### Running TypeScript with Bun Source: https://waddler.drizzle.team/docs/get-started/neon-new This command demonstrates the recommended way to run TypeScript files directly using Bun, which handles various module formats without additional configuration. ```bash bun src/index.ts ``` -------------------------------- ### Project File Structure Source: https://waddler.drizzle.team/docs/get-started/postgresql-new Illustrates the basic file structure for a Waddler project using PostgreSQL. ```tree 📦 ├ 📂 src │ └ 📜 index.ts ├ 📜 .env ├ 📜 package.json └ 📜 tsconfig.json ``` -------------------------------- ### Gel Project Initialization Source: https://waddler.drizzle.team/docs/gel/get-started/gel-new Initializes a new Gel project using the Gel CLI. This command sets up the basic project structure for interacting with a Gel database. ```bash npx gel project init ``` ```bash yarn gel project init ``` ```bash pnpm gel project init ``` ```bash bun gel project init ``` -------------------------------- ### Running TypeScript with Bun Source: https://waddler.drizzle.team/docs/get-started/nile-new Demonstrates the recommended method of running TypeScript files using 'bun', highlighting its ease of use across different module formats. ```bash bun src/index.ts ``` -------------------------------- ### Create Expo App with TypeScript Template Source: https://waddler.drizzle.team/docs/sqlite/get-started/op-sqlite-new Command to create a new Expo project pre-configured with TypeScript. This is the initial step for setting up the development environment. ```bash npx create-expo-app --template blank-typescript ``` ```bash yarn create-expo-app --template blank-typescript ``` ```bash pnpm create-expo-app --template blank-typescript ``` ```bash bun create-expo-app --template blank-typescript ``` -------------------------------- ### Run index.ts directly with bun Source: https://waddler.drizzle.team/docs/sqlite/get-started/turso-new Shows the recommended method of running TypeScript files directly using `bun`, which simplifies execution without requiring additional configuration for module formats. ```bash bun src/index.ts ``` -------------------------------- ### Gel Connection and Usage Source: https://waddler.drizzle.team/docs/gel/get-started This section focuses on the 'Gel' database driver within Waddler, covering its overview and getting started guide. ```typescript // Example for connecting using Gel (specific driver details would be here) // import { createConnection } from 'waddler'; // // async function connectWithGel() { // const connection = await createConnection({ driver: 'gel', /* Gel specific options */ }); // console.log('Connected using Gel'); // // Perform database operations... // await connection.close(); // } ``` -------------------------------- ### Install Waddler and PGlite Packages Source: https://waddler.drizzle.team/docs/get-started/pglite-new Installs the necessary Waddler and PGlite packages along with dotenv for environment variables, and tsx for running TypeScript files. Supports npm, yarn, pnpm, and bun. ```npm npm i waddler @electric-sql/pglite dotenv npm i -D tsx ``` ```yarn yarn add waddler @electric-sql/pglite dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler @electric-sql/pglite dotenv pnpm add -D tsx ``` ```bun bun add waddler @electric-sql/pglite dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and Vercel Postgres Packages Source: https://waddler.drizzle.team/docs/get-started/vercel-new Installs the Waddler library, the Vercel Postgres driver, dotenv for environment variables, and tsx for running TypeScript files. Supports npm, yarn, pnpm, and bun package managers. ```npm npm i waddler @vercel/postgres dotenv npm i -D tsx ``` ```yarn yarn add waddler @vercel/postgres dotenv yarn add -D tsx ``` ```pnpm pnpm add waddler @vercel/postgres dotenv pnpm add -D tsx ``` ```bun bun add waddler @vercel/postgres dotenv bun add -D tsx ``` -------------------------------- ### Install Waddler and mysql2 Source: https://waddler.drizzle.team/docs/mysql/get-started/singlestore-new Installs the Waddler library, the mysql2 driver, dotenv for environment variables, and tsx for running TypeScript files. ```bash npm i waddler mysql2 dotenv npm i -D tsx ``` ```bash yarn add waddler mysql2 dotenv yarn add -D tsx ``` ```bash pnpm add waddler mysql2 dotenv pnpm add -D tsx ``` ```bash bun add waddler mysql2 dotenv bun add -D tsx ``` -------------------------------- ### Connect Waddler with Existing LibSQL Client Source: https://waddler.drizzle.team/docs/sqlite/get-started/sqlite-new Initializes a Waddler connection using an existing LibSQL client instance, allowing for more control over the client setup. ```typescript import 'dotenv/config'; import { waddler } from 'waddler/libsql'; import { createClient } from '@libsql/client'; const client = createClient({ url: process.env.DATABASE_URL! }); const sql = waddler({ client }); ``` -------------------------------- ### Streaming Data from ClickHouse with Waddler Source: https://waddler.drizzle.team/docs/clickhouse/get-started/clickhouse-new Shows how to stream user data from a ClickHouse database using Waddler and the `@clickhouse/client`. This example iterates over the streamed results and logs each user record. ```typescript import 'dotenv/config'; import { createClient } from '@clickhouse/client'; import { waddler } from 'waddler/clickhouse'; async function main() { const client = createClient({ url: process.env.DATABASE_URL! }) // process.env.DATABASE_URL should look like this: http[s]://:@:/; const sql = waddler({ client }); const stream = sql`select * from ${sql.identifier('users')};`.query().stream(); console.log('Streaming users one at a time from the database.') for await (const user of stream) { console.log(user) /* const user: { id: number; name: string; age: number; email: string; } */ } await client.close(); } main(); ``` -------------------------------- ### Create Users Table Source: https://waddler.drizzle.team/docs/get-started/xata-new Executes an SQL command to create a 'users' table with an auto-incrementing ID, name, age, and a unique email field. This is an example of using the `unsafe` method for raw SQL execution. ```sql await sql.unsafe (`create table users ( id integer primary key generated always as identity, name varchar(255) not null, age integer not null, email varchar(255) not null unique ); `); ``` -------------------------------- ### Waddler Drizzle Index TS Example Source: https://waddler.drizzle.team/docs/get-started/nile-new Demonstrates using Waddler with Drizzle and Node.js (Postgres) to interact with a multi-tenant database. Includes creating tenants, todos, updating, deleting, and setting tenant context. ```typescript import 'dotenv/config'; import {waddler} from 'waddler/node-postgres' import pg from 'pg'; const {Client} = pg; const main = async () => { const client = new Client(process.env['NILEDB_URL']!); await client.connect(); const sql = waddler({client}); const tenant = { name: 'AwesomeSauce Inc.', }; await sql`insert into ${sql.identifier('tenants')}(${sql.identifier('name')}) values ${sql.values([[tenant.name]])}; `; console.log('New tenant created!') const tenants = await sql<{id: string}>`select * from ${sql.identifier('tenants')}; `; console.log('Getting all tenants from the database:', tenants) const todo = { tenant_id: tenants[0]!.id, title: 'Update pitch deck with AI stuff' }; await sql`insert into ${sql.identifier('todos')}(${sql.identifier(['tenant_id', 'title'])}) values ${sql.values([[todo.tenant_id, todo.title]])}; `; console.log('New todo created!') const todos = await sql<{id: string}>`select * from ${sql.identifier('todos')}; `; console.log('Getting all todos from the database:', todos) await sql`SET nile.tenant_id = '${sql.raw(tenants[0]!.id)}';`; console.log("Set tenant context"); // note the lack of tenant_id in the query const tenant_todos = await sql`select * from ${sql.identifier('todos')}; `; console.log('Getting all todos from the tenant virtual database:', tenant_todos) await sql`update ${sql.identifier('todos')} set ${sql.identifier('complete')} = true where ${sql.identifier({table: 'todos', column: 'id'})} = ${todos[0]!.id}; `; console.log('Todo marked as done!') await sql`delete from ${sql.identifier('todos')} where ${sql.identifier({table: 'todos', column: 'id'})} = ${todos[0]!.id}; `; console.log('Todo deleted!') await client.end(); } main(); ``` -------------------------------- ### Install Waddler and PlanetScale Packages Source: https://waddler.drizzle.team/docs/mysql/connect-planetscale Installs the necessary Waddler and PlanetScale packages using npm, yarn, pnpm, or bun. ```npm npm i waddler @planetscale/database ``` ```yarn yarn add waddler @planetscale/database ``` ```pnpm pnpm add waddler @planetscale/database ``` ```bun bun add waddler @planetscale/database ```