### Initialize Gel Project Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/gel/get-started/gel-new.mdx Use this command to start a new Gel project. Ensure you have npx installed. ```bash gel project init ``` -------------------------------- ### Install Dependencies with PNPM Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md Use this command to install all project dependencies. ```bash pnpm install ``` -------------------------------- ### Install @neondatabase/serverless Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/neon-new.mdx Install the necessary package for connecting to Neon from serverless environments. ```bash npm install @neondatabase/serverless ``` -------------------------------- ### Install postgres.js Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-postgresql.mdx Install the Waddler and postgres.js packages. ```bash waddler postgres ``` -------------------------------- ### Install Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/nile-new.mdx Installs the 'pg' package for database interaction and its TypeScript types. ```bash npm install pg npm install --save-dev @types/pg ``` -------------------------------- ### Install @clickhouse/client Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/clickhouse/get-started/clickhouse-new.mdx Use this command to install the necessary ClickHouse client package for your project. ```bash npm install @clickhouse/client ``` -------------------------------- ### Install Waddler and OP-SQLite Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/op-sqlite-new.mdx Install the necessary packages for Waddler and OP-SQLite using npm. ```bash npm install waddler @op-engineering/op-sqlite ``` -------------------------------- ### Install Waddler and PlanetScale Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/connect-planetscale.mdx Install the necessary packages for Waddler and PlanetScale integration. ```bash waddler @planetscale/database ``` -------------------------------- ### Install Waddler and PGlite Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-pglite.mdx Install the necessary packages using npm. This command installs both Waddler and the PGlite driver. ```bash npm install waddler @electric-sql/pglite ``` -------------------------------- ### Initialize Waddler with Bun SQL Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-bun-sql.mdx Use this snippet to initialize the Waddler driver with Bun SQL using the DATABASE_URL environment variable. This is the most straightforward way to get started. ```typescript import 'dotenv/config'; import { waddler } from 'waddler/bun-sql'; const sql = waddler(process.env.DATABASE_URL); const result = await sql`select 1;`; ``` -------------------------------- ### Install Waddler and Gel Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/gel/connect-gel.mdx Install the necessary Waddler and Gel packages using npm. ```bash waddler gel ``` -------------------------------- ### Install @planetscale/database Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/planetscale-new.mdx Use this command to install the PlanetScale database package for your project. ```bash npm install @planetscale/database ``` -------------------------------- ### Install mysql2 Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/singlestore-new.mdx Use this command to install the mysql2 package, which is required for connecting Waddler to a SingleStore database. ```bash npm install mysql2 ``` -------------------------------- ### Setup Database Connection Environment Variable Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/postgresql-new.mdx Sets up the DATABASE_URL environment variable for database connection. ```bash DATABASE_URL=postgresql://user:password@host:port/database ``` -------------------------------- ### Setup Database Connection URL Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/bun-sql-new.mdx Configure the DATABASE_URL environment variable for your database connection. ```bash DATABASE_URL=sqlite://path/to/your/database.sqlite ``` -------------------------------- ### Install Waddler and LibSQL Client Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/connect-turso.mdx Install the Waddler package and the official libSQL client for Node.js environments. ```bash waddler @libsql/client ``` -------------------------------- ### Install pg-query-stream Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/clickhouse/query-stream.mdx Install the `pg-query-stream` package using npm to enable streaming capabilities for PostgreSQL clients. ```bash npm install pg-query-stream ``` -------------------------------- ### Start Local Development Server Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md Runs the local development server, typically accessible at `localhost:4321`. ```bash pnpm run dev ``` -------------------------------- ### Install Waddler and MySQL2 Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/connect-mysql.mdx Install the necessary packages for Waddler and the MySQL2 driver using npm. ```bash npm install waddler mysql2 ``` -------------------------------- ### Complete example with sql.identifier and sql.default Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/clickhouse/sql-default.mdx This example demonstrates a more comprehensive use case, combining `sql.identifier` for table and column names with `sql.values` and `sql.default` for inserting data. It also includes a `returning` clause. ```typescript const table = sql.identifier("users") const columns = sql.identifier(["id", "name", "age"]); const values = sql.values([ [sql.default, "Oleksii", 20], [sql.default, "Alex", 23], ]); await sql`insert into ${table} (${columns}) values ${values} returning ${columns}`; ``` ```sql insert into `users` (`id`, `name`, `age`) values (default, 'Oleksii', 20), (default, 'Alex', 23); ``` -------------------------------- ### Equivalent node-postgres setup with Pool Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-overview.mdx This demonstrates an equivalent setup to the direct node-postgres connection, explicitly using a pg Pool instance. ```typescript // above is equivalent to import { waddler } from "waddler/node-postgres"; import { Pool } from "pg"; const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); const sql = waddler({ client: pool }); ``` -------------------------------- ### Install Waddler and PostgreSQL Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-nile.mdx Install the necessary Waddler and PostgreSQL packages using npm. ```bash npm install waddler pg npm install -D drizzle-kit ``` -------------------------------- ### Install node-postgres Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-postgresql.mdx Install the necessary Waddler and node-postgres packages, including types for TypeScript. ```bash waddler pg -D @types/pg ``` -------------------------------- ### PlanetScale Serverless Metadata Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/logger.mdx This example demonstrates the metadata structure for the `planetscale-serverless` driver, including headers, fields, and statement details. ```typescript // metadata type type metadataType = { headers: string[], types: Types, fields: { name: string, type: string, table?: string, orgTable?: string | null, database?: string | null, orgName?: string | null, columnLength?: number | null, charset?: number | null, decimals?: number, flags?: number | null, columnType?: string | null; }[], size: number, statement: string, insertId: string, rowsAffected: number, time: number } // metadata example { headers: [ ':vtg1 /* INT64 */' ], types: { ':vtg1 /* INT64 */': 'INT64' }, fields: [ { name: ':vtg1 /* INT64 */', type: 'INT64', charset: 63, flags: 32768 } ], rowsAffected: 0, insertId: '0', size: 1, statement: 'select 1;', time: 1.23636 } ``` -------------------------------- ### Install postgres Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/supabase-new.mdx Installs the 'postgres' npm package. Ensure you have npm or yarn available. ```bash npm install postgres ``` -------------------------------- ### Install Expo SQLite Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/expo-new.mdx Install the expo-sqlite package using the Expo CLI. ```bash expo install expo-sqlite ``` -------------------------------- ### Initialize Waddler with MySQL2 Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/connect-mysql.mdx Initialize Waddler with the mysql2 driver using a database URL. This is the simplest way to get started. ```typescript import { waddler } from "waddler/mysql2"; const sql = waddler(process.env.DATABASE_URL); const result = await sql`select 1;`; ``` -------------------------------- ### Install Waddler and Neon Serverless Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-neon.mdx Install the necessary packages for connecting Waddler to Neon serverless databases using npm. ```bash npm install waddler @neondatabase/serverless ``` -------------------------------- ### Setup Database Connection Environment Variable Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/neon-new.mdx Configure the DATABASE_URL environment variable to store your Neon database connection string. ```bash export DATABASE_URL='postgresql://user:password@host:port/database' ``` -------------------------------- ### Install node-postgres Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/postgresql-new.mdx Installs the node-postgres package and its TypeScript types. ```bash npm install pg npm install -D @types/pg ``` -------------------------------- ### Install Waddler and Xata Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-xata.mdx Install the required packages for Waddler and the Xata client. This is a prerequisite for connecting Waddler to Xata. ```bash waddler @xata.io/client ``` -------------------------------- ### Setup Connection Environment Variable Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/singlestore-new.mdx Configure your environment variables to include the DATABASE_URL for your SingleStore connection. This is essential for Waddler to establish a connection. ```bash DATABASE_URL=mysql2://user:password@host:port/database ``` -------------------------------- ### Install Waddler and ClickHouse Client Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/clickhouse/connect-clickhouse.mdx Install the necessary packages for Waddler and the ClickHouse client. This is the first step to enable ClickHouse integration. ```bash waddler @clickhouse/client ``` -------------------------------- ### MySQL2 Metadata Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/logger.mdx This example shows the structure of metadata returned by the `mysql2` driver, including catalog, schema, name, and type information. ```typescript // metadata type type metadataType = { catalog: string, charsetNr?: number, db?: string, schema?: string, characterSet?: number, decimals: number, default?: any, flags: number | string[], length?: number, name: string, orgName: string, orgTable: string, protocol41?: boolean, table: string, type?: number, columnType?: number, zerofill?: boolean, typeName?: string, encoding?: string, columnLength?: number }[] // metadata example [ { catalog: 'def', schema: '', name: '1', orgName: '', table: '', orgTable: '', characterSet: 63, encoding: 'binary', columnLength: 2, type: 8, flags: [ 'NOT NULL' ], decimals: 0, typeName: 'LONGLONG' } ] ``` -------------------------------- ### Data Structure Example: Progress and Weeks Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md An example structure for tracking progress over weeks, including dates and details. ```yaml progress: number weeks: - date: start: "YYYY-MM-DD" details: - string ``` -------------------------------- ### Install Waddler and TiDB Serverless Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/connect-tidb.mdx Install the necessary packages for Waddler and the TiDB Serverless HTTP driver using npm. ```bash waddler @tidbcloud/serverless ``` -------------------------------- ### SQL Query Output Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/duckdb/tosql.mdx This shows the expected output format from the .toSQL() method, displaying the query string and an array of parameters. ```shell { query: "select * from users", params: [], } ``` ```shell { query: "select * from users where id = $1", params: [ 10 ], } ``` -------------------------------- ### Get Help with Astro CLI Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md Displays help information for using the Astro CLI. ```bash pnpm run astro -- --help ``` -------------------------------- ### Install Waddler and Types for Bun Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/bun-sql-new.mdx Install the Waddler package and TypeScript types for Bun using npm. ```bash npm install waddler npm install -D @types/bun ``` -------------------------------- ### Setup Supabase Connection Variables Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/supabase-new.mdx Sets up the DATABASE_URL environment variable for connecting to your Supabase instance. This is crucial for Waddler to establish a database connection. ```bash echo "DATABASE_URL='postgresql://postgres:YOUR_PASSWORD@YOUR_HOST:5432/YOUR_DATABASE'" >> .env ``` -------------------------------- ### Install pg-query-stream for Node-Postgres Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/chunked.mdx To enable chunked streaming with node-postgres, install the `pg-query-stream` package. This is a prerequisite for using the `.chunked()` method with this driver. ```bash pg-query-stream ``` -------------------------------- ### Initialize Waddler with Existing Gel Client Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/gel/connect-gel.mdx Initialize Waddler using an existing Gel client instance. Ensure the 'gel' package is installed. ```typescript // Make sure to install the 'gel' package import { waddler } from "waddler/gel"; import { createClient } from "gel"; const gelClient = createClient(); const sql = waddler({ client: gelClient }); const result = await sql`select 1;`; ``` -------------------------------- ### Setup Environment Variable for Nile DB Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/nile-new.mdx Sets up the NILEDB_URL environment variable, which is required for connecting to the Nile database. ```bash export NILEDB_URL="postgres://user:password@host:port/database" ``` -------------------------------- ### Create a Table in PlanetScale Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/planetscale-new.mdx Example of creating a 'users' table with an 'id' and 'name' column in your PlanetScale database. ```typescript import { Database } from '@planetscale/database' const db = new Database({ url: process.env.PLANETSCALE_CONNECTION_STRING }) await db.execute(` CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL ) `) console.log('Table created successfully!') ``` -------------------------------- ### Initialize postgres.js Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-neon.mdx Initialize the Waddler driver for postgres.js. Ensure the 'postgres' package is installed and DATABASE_URL is set. ```typescript // Make sure to install the 'postgres' package import { waddler } from 'waddler/postgres-js'; const sql = waddler(process.env.DATABASE_URL); const result = await sql`select 1;`; ``` -------------------------------- ### Set Up PlanetScale Connection Variables Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/planetscale-new.mdx Create a .env file and add your PlanetScale database credentials. Refer to PlanetScale docs for specific values. ```plaintext DATABASE_HOST= DATABASE_USERNAME= DATABASE_PASSWORD= ``` -------------------------------- ### Setup Database Connection Environment Variable Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/mysql-new.mdx Configure your environment variables to include the DATABASE_URL, which holds your MySQL connection string. This is essential for Waddler to establish a connection. ```bash DATABASE_URL="mysql://user:password@host:port/database" ``` -------------------------------- ### Equivalent node-postgres setup with Pool Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/connect-overview.mdx This shows an alternative way to set up Waddler with node-postgres by explicitly creating a Pool instance and passing it to Waddler. ```typescript import { waddler } from "waddler/node-postgres"; import { Pool } from "pg"; const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); const sql = waddler({ client: pool }); ``` -------------------------------- ### Initialize node-postgres Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-neon.mdx Initialize the Waddler driver for node-postgres. Ensure the 'pg' package is installed and DATABASE_URL is set. ```typescript // Make sure to install the 'pg' package import { waddler } from 'waddler/node-postgres'; const sql = waddler(process.env.DATABASE_URL); const result = await sql`select 1;`; ``` -------------------------------- ### Initialize node-postgres with existing driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-planetscale-postgres.mdx Integrate Waddler with an existing node-postgres Pool instance. Ensure the 'pg' package is installed. ```typescript // Make sure to install the 'pg' package import { waddler } from "waddler/node-postgres"; import pg from 'pg'; const { Pool } = pg; const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); const sql = waddler({ client: pool }); const result = await sql`select 1;`; ``` -------------------------------- ### Build Production Site Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md Compiles the project for production deployment, outputting to the `./dist/` directory. ```bash pnpm run build ``` -------------------------------- ### Initialize Waddler Driver and Query Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-supabase.mdx Initialize the Waddler driver with your Supabase DATABASE_URL and execute a simple query. This is the most basic setup for connecting. ```typescript import { waddler } from 'waddler/postgres-js' const sql = waddler(process.env.DATABASE_URL); const result = await sql`select 1;`; ``` -------------------------------- ### Preview Production Build Locally Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md Allows you to preview the production build locally before deploying. ```bash pnpm run preview ``` -------------------------------- ### Install duckdb-neo Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/duckdb/get-started/duckdb-neo-new.mdx Installs the duckdb-neo package, which is required for Waddler to connect to DuckDB. ```bash npm install @duckdb/node-api ``` -------------------------------- ### Install Waddler with node-postgres Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-prisma-postgres.mdx Install the Waddler package with the node-postgres driver. This is required to use Waddler with the pg package. ```bash waddler pg ``` -------------------------------- ### Initialize Bun SQL Connection with Existing Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/postgresql/ConnectBun.mdx Initialize a Bun SQL connection by providing an existing Bun SQL client. This is useful if you need more control over the client's lifecycle or configuration. ```typescript import 'dotenv/config'; import { waddler } from 'waddler/bun-sql'; import { SQL } from 'bun'; const client = new SQL(process.env.DATABASE_URL!); await client.connect(); const sql = waddler({ client }); ``` -------------------------------- ### Install Waddler and DuckDB Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/duckdb/connect-duckdb-neo.mdx Install the necessary packages for Waddler and the DuckDB Node.js API using npm. ```bash npm install waddler @duckdb/node-api ``` -------------------------------- ### Install Waddler Packages for SQLite Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/sqlite-new.mdx Installs the necessary packages for Waddler to interact with an SQLite database using the libsql client. ```bash npm install @waddler/waddler @libsql/client ``` -------------------------------- ### Install Waddler Package Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/connect-cloudflare-d1.mdx Install the Waddler package using npm. This is the first step to enable Waddler functionality in your project. ```bash waddler ``` -------------------------------- ### Install Waddler with Vercel Postgres Support Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/vercel-new.mdx Use this command to install the necessary package for Waddler to interact with Vercel Postgres. ```bash npm install @vercel/postgres ``` -------------------------------- ### Basic Project File Structure Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/FileStructure.mdx This illustrates the fundamental organization of files and directories within the project root. It includes the source directory, environment configuration, package manifest, and TypeScript configuration. ```plaintext 📦 ├ 📂 src │ └ 📜 index.ts ├ 📜 .env ├ 📜 package.json └ 📜 tsconfig.json ``` -------------------------------- ### DuckDB Metadata Types and Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/duckdb/logger.mdx Defines the `metadataType` for DuckDB queries, including `ResultReturnType` and `StatementType` enums. An example of metadata is provided. ```ts // metadata type type metadataType = { get returnType(): ResultReturnType; get statementType(): StatementType; get columnCount(): number; get rowsChanged(): number; } // where ResultReturnType is enum ResultType { INVALID = 0, CHANGED_ROWS = 1, NOTHING = 2, QUERY_RESULT = 3, } // and StatementType is enum StatementType { INVALID = 0, SELECT = 1, INSERT = 2, UPDATE = 3, EXPLAIN = 4, DELETE = 5, PREPARE = 6, CREATE = 7, EXECUTE = 8, ALTER = 9, TRANSACTION = 10, COPY = 11, ANALYZE = 12, VARIABLE_SET = 13, CREATE_FUNC = 14, DROP = 15, EXPORT = 16, PRAGMA = 17, VACUUM = 18, CALL = 19, SET = 20, LOAD = 21, RELATION = 22, EXTENSION = 23, LOGICAL_PLAN = 24, ATTACH = 25, DETACH = 26, MULTI = 27, } // metadata example { columnCount: 1, returnType: 3, rowsChanged: 0, statementType: 1 } ``` -------------------------------- ### Initialize postgres.js driver and query Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-prisma-postgres.mdx Initialize the Waddler client with a postgres.js query client and execute a simple query. Ensure the 'postgres' package is installed and the DATABASE_URL environment variable is set. ```typescript import { waddler } from 'waddler/postgres-js'; import postgres from 'postgres'; const queryClient = postgres(process.env.DATABASE_URL); const sql = waddler({ client: queryClient }); const result = await sql`select 1;`; ``` -------------------------------- ### Install Waddler and dotenv Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/do-new.mdx Use npm to install Waddler and dotenv for managing environment variables, and wrangler and @cloudflare/workers-types as development dependencies. ```bash npm install waddler dotenv npm install -D wrangler @cloudflare/workers-types ``` -------------------------------- ### Seed and Query MySQL Database Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/get-started/mysql-new.mdx This example shows how to insert data into the 'users' table and then query it to retrieve all user records. It utilizes Waddler's ORM features for database interactions. ```typescript import { db, users, NewUser } from "./db"; const newUser: NewUser = { name: "John Doe", email: "john.doe@example.com", }; await db.insert(users).values(newUser); const allUsers = await db.select(users); console.log(allUsers); ``` -------------------------------- ### Install Waddler Core and Dev Dependencies Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/InstallPackages.mdx Use this command to install the main Waddler package along with dotenv and development tools like tsx. ```bash npm install waddler dotenv npm install -D tsx ``` -------------------------------- ### Install Waddler and Gel Packages Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/gel/get-started/gel-new.mdx Install Waddler and Gel packages using npm. Include tsx as a dev dependency for running TypeScript files. ```bash npm install waddler gel -D tsx ``` -------------------------------- ### Add Database Connection Variable to .env Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/SetupEnv.mdx Create a .env file in your project root and add your database connection variable. ```plaintext $env_variable$= ``` -------------------------------- ### Example chunked result format Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/chunked.mdx This is an example of how a chunk of data might be formatted when streaming results using the `.chunked()` method. Each chunk contains an array of objects. ```json [ { id: 1, name: "Alex", }, { id: 2, name: "Oleksii", } ] … ``` -------------------------------- ### TiDB Serverless Metadata Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/logger.mdx This example shows the metadata structure returned by the `tidb-serverless` driver when `rowMode` is set to 'object', including statement and type information. ```typescript // metadata returns only with `rowMode` equals to 'object' type metadataType = { types: Record | null, statement: string, rowCount: number | null, rowsAffected: number | null, lastInsertId: string | null } // metadata example { statement: 'select 1;', types: { '1': 'BIGINT' }, rowsAffected: null, lastInsertId: null, rowCount: 1 } ``` -------------------------------- ### xata-http Metadata Type and Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/logger.mdx The `xata-http` driver provides metadata focused on columns and optional warnings. This snippet shows the type definition and an example of the metadata object. ```typescript // metadata type type metadataType = { columns: Array<{ name: string; type: string; }>; warning?: string; } // metadata example { rows: undefined, warning: undefined, columns: [ { name: '?column?', type: 'text' } ] } ``` -------------------------------- ### Initialize Waddler with Existing Driver Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/connect-supabase.mdx Initialize Waddler by providing an existing `postgres` client instance. This is useful if you already have a `postgres` client configured. ```typescript import { waddler } from 'waddler/postgres-js' import postgres from 'postgres' const client = postgres(process.env.DATABASE_URL) const sql = waddler({ client }); const result = await sql`select 1;`; ``` -------------------------------- ### pglite Metadata Type and Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/logger.mdx The `pglite` driver's metadata includes affected rows and field information. This snippet shows the type definition and an example of the metadata object. ```typescript // metadata type type metadataType = { affectedRows?: number; fields: { name: string; dataTypeID: number; }[]; blob?: Blob; } // metadata example { fields: [ { name: '?column?', dataTypeID: 25 } ], affectedRows: 0 } ``` -------------------------------- ### neon-serverless Metadata Type and Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/logger.mdx The `neon-serverless` driver provides metadata similar to `node-postgres`, including command, row count, OID, and field details. This snippet shows the type definition and an example. ```typescript // metadata type type metadataType = { command: string; rowCount: number | null; oid: number; fields: { name: string; tableID: number; columnID: number; dataTypeID: number; dataTypeSize: number; dataTypeModifier: number; format: string; }[]; } // metadata example: { command: 'SELECT', fields: [ Field { name: '?column?', tableID: 0, columnID: 0, dataTypeID: 25, dataTypeSize: -1, dataTypeModifier: -1, format: 'text' } ], oid: null, rowCount: 1 } ``` -------------------------------- ### Initialize Waddler with LibSQL (Web) Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/sqlite/LibsqlTabs.mdx Use this for initializing Waddler with LibSQL in web browser environments. Make sure DATABASE_URL and DATABASE_AUTH_TOKEN are configured. ```typescript import { waddler } from 'waddler/libsql/web'; const sql = waddler({ connection: { url: process.env.DATABASE_URL, authToken: process.env.DATABASE_AUTH_TOKEN }}); ``` -------------------------------- ### Initialize LibSQL Connection Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/sqlite/ConnectLibsql.mdx Initialize a LibSQL connection using the DATABASE_URL environment variable. Ensure 'dotenv/config' is imported if using environment variables. ```typescript import 'dotenv/config'; import { waddler } from 'waddler/libsql'; const sql = waddler(process.env.DATABASE_URL!); ``` ```typescript import 'dotenv/config'; import { waddler } from 'waddler/libsql'; // You can specify any property from the libsql connection options const sql = waddler({ connection: { url: process.env.DATABASE_URL! }}}); ``` -------------------------------- ### Seed and Query D1 Database with Waddler Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/d1-new.mdx This example demonstrates inserting a new user record and then querying all users from the 'users' table using Waddler. It includes creating a user, logging a confirmation, and returning the query results as JSON. ```typescript import { waddler } from 'waddler/d1'; export interface Env { : D1Database; } export default { async fetch(request: Request, env: Env) { const sql = waddler({ client: env. }); const user = [ 'John', 30, 'john@example.com', ]; await sql`insert into ${sql.identifier('users')}(${sql.identifier(['name', 'age', 'email'])}) values ${sql.values([user])}; `; console.log('New user created!') const users = await sql`select * from ${sql.identifier('users')}; `; return Response.json(users); }, }; ``` -------------------------------- ### neon-http Metadata Type and Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/logger.mdx The `neon-http` driver provides metadata including fields, command type, row count, and array mode. This snippet shows the type definition and an example of the metadata object. ```typescript // metadata type type metadataType = { fields: { name: string; tableID: number; columnID: number; dataTypeID: number; dataTypeSize: number; dataTypeModifier: number; format: string; }[]; command: string; rowCount: number; rowAsArray: ArrayMode; } // metadata example { command: 'SELECT', fields: [ { name: '?column?', dataTypeID: 25, tableID: 0, columnID: 0, dataTypeSize: -1, dataTypeModifier: -1, format: 'text' } ], rowAsArray: false, rowCount: 1 } ``` -------------------------------- ### Basic SQL Template with Different Drivers Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/landing/showcase.mdx Shows how to import and use Waddler with different database drivers. The first example uses a generic import, while the second specifically imports from 'waddler/duckdb-neo'. The SQL template allows embedding values directly. ```ts import { waddler } from 'waddler/...'; const sql = waddler({ dbUrl: "" }) await sql`select * from "users" where "id" = ${10}`; ``` ```ts import { waddler } from 'waddler/duckdb-neo'; const sql = waddler({ dbUrl: ":memory:" }) await sql`select * from "users" where "id" = ${10}`; ``` ```sql select * from "users" where "id" = $1; -- 10 will be passed as a param [10] ``` -------------------------------- ### node-postgres Metadata Type and Example Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/pg/logger.mdx The `node-postgres` driver provides detailed metadata for queries, including command type, row count, OID, and field information. This snippet shows the type definition and an example of the metadata object. ```typescript // metadata type type metadataType = { command: string; rowCount: number | null; oid: number; fields: { name: string; tableID: number; columnID: number; dataTypeID: number; dataTypeSize: number; dataTypeModifier: number; format: string; }[]; } // also can include fields such as: // '_parsers', '_types', 'RowCtor', 'rowAsArray', '_prebuiltEmptyResultObject'; // metadata example { command: 'SELECT', rowCount: 1, oid: null, fields: [ Field { name: '?column?', tableID: 0, columnID: 0, dataTypeID: 25, dataTypeSize: -1, dataTypeModifier: -1, format: 'text' } ], _parsers: [ [Function: noParse] ], _types: { getTypeParser: [Function: getTypeParser] }, RowCtor: null, rowAsArray: false, _prebuiltEmptyResultObject: { '?column?': null } } ``` -------------------------------- ### Project Structure: Documentation Content Source: https://github.com/drizzle-team/waddler-website/blob/main/README.md MDX files for documentation are located in the `src/content/documentation` directory. ```text ├── src/ │ ├── content/ │ │ └── documentation ``` -------------------------------- ### Complete Insert with SQL DEFAULT and Identifiers Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/mysql/sql-default.mdx This example demonstrates a complete insert statement using `sql.default` for the `id` column and `sql.identifier` for table and column names. It also includes a `returning` clause. ```typescript const table = sql.identifier("users") const columns = sql.identifier(["id", "name", "age"]); const values = sql.values([ [sql.default, "Oleksii", 20], [sql.default, "Alex", 23], ]); await sql`insert into ${table} (${columns}) values ${values} returning ${columns}`; ``` ```sql insert into users ( id, name, age ) values (default, 'Oleksii', 20), (default, 'Alex', 23); ``` -------------------------------- ### Initialize Gel Driver and Query Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/gel/connect-gel.mdx Initialize the Waddler Gel driver with a database URL and execute a simple SQL query. ```typescript // Make sure to install the 'gel' package import { waddler } from 'waddler/gel'; const sql = waddler(process.env.DATABASE_URL); const result = await sql`select 1;`; ``` -------------------------------- ### Connect Waddler to PostgreSQL Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/planetscale-postgres-new.mdx Initializes Waddler with a PostgreSQL client. This setup is required before performing database operations. ```typescript import 'dotenv/config'; import pg from 'pg'; import { waddler } from 'waddler/node-postgres'; const { Client } = pg; async function main() { const client = new Client(process.env.DATABASE_URL!); await client.connect(); const sql = waddler({ client }); // Example query const users = await sql`SELECT * FROM users`; console.log(users); await client.end(); } main(); ``` -------------------------------- ### Initialize Bun SQL Connection Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/postgresql/ConnectBun.mdx Initialize a Bun SQL connection using the DATABASE_URL environment variable. Ensure you have 'dotenv/config' imported to load environment variables. ```typescript import 'dotenv/config'; import { waddler } from 'waddler/bun-sql'; const sql = waddler(process.env.DATABASE_URL!); ``` ```typescript import 'dotenv/config'; import { waddler } from 'waddler/bun-sql'; // You can specify any property from the bun sql connection options const sql = waddler({ connection: { url: process.env.DATABASE_URL! }}); ``` -------------------------------- ### Durable SQLite Setup and Operations in Cloudflare Worker Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/do-new.mdx This snippet shows the complete setup for a Durable Object in Cloudflare Workers using Waddler for SQLite. It includes constructor initialization, table creation, data insertion, and selection. The fetch handler demonstrates two options for interacting with the Durable Object: bundling operations for maximum performance or direct query calls for debugging. ```typescript /// import { type DurableSqliteSQL, waddler } from 'waddler/durable-sqlite'; import { DurableObject } from 'cloudflare:workers' export class MyDurableObject extends DurableObject { sql: DurableSqliteSQL; constructor(ctx: DurableObjectState, env: Env) { super(ctx, env); this.sql = waddler({ client: ctx.storage }); // Ensure all tables are created before accepting queries. ctx.blockConcurrencyWhile(async () => { await this.createTable(); }); } aync insertAndList(user: any[]) { await this.insert(user); return this.select(); } aync insert(user: any[]) { await this.sql` insert into ${this.sql.identifier('users')}(${this.sql.identifier(['name', 'age', 'email'])}) values ${this.sql.values([user])}; `.run(); } aync select(): Promise { const users = await this.sql`select * from ${this.sql.identifier('users')};`.all(); return users; } aync createTable() { await this.sql.unsafe(`create table if not exists users ( id integer primary key autoincrement, name text not null, age integer not null, email text not null unique ); `).run(); } } export default { /** * This is the standard fetch handler for a Cloudflare Worker * * @param request - The request submitted to the Worker from the client * @param env - The interface to reference bindings declared in wrangler.toml * @param ctx - The execution context of the Worker * @returns The response to be sent back to the client */ aync fetch(request, env: Env): Promise { const id = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname); const stub = env.MY_DURABLE_OBJECT.get(id); await stub.allTypesInSqlUnsafe(); await stub.allTypesInSqlValues(); await stub.sqlStream(); // Option A - Maximum performance. // Prefer to bundle all the database interaction within a single Durable Object call // for maximum performance, since database access is fast within a DO. const usersAll = await stub.insertAndList([ 'John', 30, 'johnA@example.com', ]); console.log('New user created. Getting all users from the database:', usersAll); // Option B - Slow but maybe useful sometimes for debugging. // You can also directly call individual queries if they are exposed // but keep in mind every query is a round-trip to the Durable Object instance. await stub.insert([ 'John', 30, 'johnB@example.com', ]); console.log('New user created!'); const users = await stub.select(); console.log('Getting all users from the database:', users); return Response.json(users); }, } ``` -------------------------------- ### Initialize PlanetScale Connection with Environment Variables Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/mysql/ConnectPlanetScale.mdx Use this method to initialize the Waddler connection by providing database credentials via environment variables. Ensure `DATABASE_HOST`, `DATABASE_USERNAME`, and `DATABASE_PASSWORD` are set. ```typescript import { waddler } from "waddler/planetscale-serverless"; const sql = waddler({ connection: { host: process.env.DATABASE_HOST!, username: process.env.DATABASE_USERNAME!, password: process.env.DATABASE_PASSWORD!, }}); // You can also connect to database using connection string // const sql = waddler(process.env.PLANETSCALE_CONNECTION_STRING!) ``` -------------------------------- ### Connect to MySQL with Configuration Object Source: https://github.com/drizzle-team/waddler-website/blob/main/src/mdx/get-started/mysql/ConnectMySQL.mdx Provide connection details through a configuration object, specifying properties like 'uri' for the connection string. ```typescript import 'dotenv/config'; import { waddler } from "waddler/mysql2"; // You can specify any property from the mysql2 connection options const sql = waddler({ connection: { uri: process.env.DATABASE_URL }}); ``` -------------------------------- ### Connect to Bun:SQLite Database Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/sqlite/get-started/bun-sqlite-new.mdx Establish a connection to your Bun:SQLite database using the configured environment variables. ```typescript import { Database } from "@waddler/database"; const db = new Database({ connectionString: process.env.DB_FILE_NAME, }); ``` -------------------------------- ### Seed and Query the Database Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/planetscale-postgres-new.mdx Inserts data into the 'users' table and then queries it. This example demonstrates basic data manipulation with node-postgres. ```typescript import 'dotenv/config'; import pg from 'pg'; import { waddler } from 'waddler/node-postgres'; const { Client } = pg; async function main() { const client = new Client(process.env.DATABASE_URL!); await client.connect(); const sql = waddler({ client }); // Seed the database await sql` INSERT INTO users (name, age, email) VALUES ('Alice', 30, 'alice@example.com'), ('Bob', 25, 'bob@example.com'); `; console.log('Data inserted into `users` table.'); // Query the database const users = await sql`SELECT * FROM users`; console.log('Users from database:', users); await client.end(); } main(); ``` -------------------------------- ### Connect Waddler to Vercel Postgres Source: https://github.com/drizzle-team/waddler-website/blob/main/src/content/docs/get-started/vercel-new.mdx This component likely handles the initial connection setup between Waddler and your Vercel Postgres instance. ```astro ```