### Deno Setup Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Configuration for Deno users, including an example import_map.json. ```APIDOC ### Deno This package uses/extends some [Kysely](https://github.com/koskimas/kysely) types and classes, which are imported using its NPM package name -- not a relative file path or CDN url. `SurrealDbWebSocketsDialect` uses `surrealdb.js` which is imported using its NPM package name -- not a relative file path or CDN url. To fix that, add an [`import_map.json`](https://deno.land/manual@v1.26.1/linking_to_external_code/import_maps) file. ```json { "imports": { "kysely": "npm:kysely@^0.25.0", "surrealdb.js": "https://deno.land/x/surrealdb@v0.5.0" // optional - only if you're using `SurrealDbWebSocketsDialect` } } ``` ``` -------------------------------- ### Installation Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Instructions for installing the kysely-surrealdb package via npm, yarn, or pnpm. ```APIDOC ## Installation #### NPM 7+ ```bash npm i kysely-surrealdb ``` #### NPM <7 ```bash npm i kysely-surrealdb kysely surrealdb.js ``` #### Yarn ```bash yarn add kysely-surrealdb kysely surrealdb.js ``` #### PNPM ```bash pnpm add kysely-surrealdb kysely surrealdb.js ``` > `surrealdb.js` is an optional peer dependency. It's only needed if you want to use `SurrealDbWebSocketsDialect`. If you don't need it, you can remove `surreal.js` from the install commands above. ``` -------------------------------- ### Install kysely-surrealdb via Yarn Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Installs the kysely-surrealdb package and its dependencies using Yarn. 'kysely' and 'surrealdb.js' are also installed, with 'surrealdb.js' being optional for the WebSockets dialect. ```bash yarn add kysely-surrealdb kysely surrealdb.js ``` -------------------------------- ### SurrealDB HTTP Connection Setup with Kysely Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Sets up a Kysely instance to connect to SurrealDB using the HTTP dialect. This is suitable for serverless functions and environments requiring stateless communication. It requires the 'kysely-surrealdb' and 'undici' libraries. ```typescript import {Kysely} from 'kysely' import {SurrealDatabase, SurrealDbHttpDialect, type SurrealEdge} from 'kysely-surrealdb' import {fetch} from 'undici' // Define your database schema interface Person { first_name: string | null last_name: string | null age: number } interface Pet { name: string owner_id: string | null } interface Own { time: { adopted: string } | null } interface Database { person: Person own: SurrealEdge // Graph edge table pet: Pet } // Initialize with HTTP dialect const db = new Kysely>({ dialect: new SurrealDbHttpDialect({ database: 'test', fetch, // Use built-in fetch for Node 18+, undici for 16.8+, or node-fetch for older versions hostname: 'localhost:8000', namespace: 'test', password: 'root', username: 'root', }), }) // Execute standard Kysely queries const people = await db .selectFrom('person') .where('age', '>', 18) .selectAll() .execute() ``` -------------------------------- ### HTTP Dialect Usage Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Example of setting up Kysely with SurrealDB using the HTTP dialect in Node.js. ```APIDOC ### HTTP Dialect [SurrealDB](https://www.surrealdb.com/)'s [HTTP endpoints](https://surrealdb.com/docs/integration/http) allow executing [SurrealQL](https://surrealdb.com/docs/surrealql) queries in the browser and are a great fit for serverless functions and other auto-scaling compute services. #### Node.js 16.8+ Older node versions are supported as well, just swap [`undici`](https://github.com/nodejs/undici) with [`node-fetch`](https://github.com/node-fetch/node-fetch). ```ts import {Kysely} from 'kysely' import {SurrealDatabase, SurrealDbHttpDialect, type SurrealEdge} from 'kysely-surrealdb' import {fetch} from 'undici' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } const db = new Kysely>({ dialect: new SurrealDbHttpDialect({ database: '', fetch, hostname: '', // e.g. 'localhost:8000' namespace: '', password: '', username: '', }), }) ``` ``` -------------------------------- ### Install kysely-surrealdb via PNPM Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Installs the kysely-surrealdb package and its dependencies using PNPM. 'kysely' and 'surrealdb.js' are also installed, with 'surrealdb.js' being optional for the WebSockets dialect. ```bash pnpm add kysely-surrealdb kysely surrealdb.js ``` -------------------------------- ### Install kysely-surrealdb via NPM Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Installs the kysely-surrealdb package and its dependencies using NPM. For NPM versions below 7, 'kysely' and 'surrealdb.js' are also installed. 'surrealdb.js' is optional and only needed for the WebSockets dialect. ```bash npm i kysely-surrealdb ``` ```bash npm i kysely-surrealdb kysely surrealdb.js ``` -------------------------------- ### Use SurrealKysely Query Builder with HTTP Dialect Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Demonstrates initializing and using the SurrealKysely query builder, which extends Kysely with SurrealQL specific query builders. This example shows how to create a 'person' record using the 'create' statement and return specific fields. ```typescript import {SurrealDbHttpDialect, SurrealKysely, type SurrealEdge} from 'kysely-surrealdb' import {fetch} from 'undici' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } const db = new SurrealKysely({ dialect: new SurrealDbHttpDialect({ database: '', fetch, hostname: '', namespace: '', password: '', username: '', }), }) await db .create('person:100') .set({ first_name: 'Jennifer', age: 15, }) .return('none') .execute() ``` -------------------------------- ### WebSockets Dialect Usage Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Example of setting up Kysely with SurrealDB using the WebSockets dialect, with and without a token. ```APIDOC ### WebSockets Dialect ```ts import {Kysely} from 'kysely' import {SurrealDatabase, SurrealDbWebSocketsDialect, type SurrealEdge} from 'kysely-surrealdb' import Surreal from 'surrealdb.js' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } // with username and password const db = new Kysely>({ dialect: new SurrealDbWebSocketsDialect({ database: '', Driver: Surreal, hostname: '', // e.g. 'localhost:8000' namespace: '', password: '', // scope: '', // optional username: '', }), }) // alternatively, with a token const dbWithToken = new Kysely>({ dialect: new SurrealDbWebSocketsDialect({ database: '', Driver: Surreal, hostname: '', // e.g. 'localhost:8000' namespace: '', token: '', }), }) ``` ``` -------------------------------- ### SurrealDB WebSocket Connection Setup with Kysely Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Configures Kysely to connect to SurrealDB using the WebSocket dialect with either username/password or JWT token authentication. This provides persistent connections and requires the 'kysely-surrealdb' and 'surrealdb.js' libraries. ```typescript import {Kysely} from 'kysely' import {SurrealDatabase, SurrealDbWebSocketsDialect, type SurrealEdge} from 'kysely-surrealdb' import Surreal from 'surrealdb.js' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } // With username and password authentication const db = new Kysely>({ dialect: new SurrealDbWebSocketsDialect({ database: 'test', Driver: Surreal, hostname: 'localhost:8000', namespace: 'test', password: 'root', username: 'root', // scope: 'user_scope', // Optional: authentication scope }), }) // Alternative: With JWT token authentication const dbWithToken = new Kysely>({ dialect: new SurrealDbWebSocketsDialect({ database: 'test', Driver: Surreal, hostname: 'localhost:8000', namespace: 'test', token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...', }), }) // Execute queries const pets = await db.selectFrom('pet').selectAll().execute() ``` -------------------------------- ### Query Execution Methods Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Demonstrates the usage of `execute()`, `executeTakeFirst()`, and `executeTakeFirstOrThrow()` for executing queries and retrieving results. ```APIDOC ## Query Execution Methods All query builders provide consistent execution methods: `execute()`, `executeTakeFirst()`, and `executeTakeFirstOrThrow()`. ### `execute()` Returns an array of all results from the query. ```typescript // execute() - Returns array of all results const allPeople = await db.create('person').set({ name: 'Test' }).execute() // Returns: Person[] ``` ### `executeTakeFirst()` Returns the first result of the query, or `undefined` if no results are found. ```typescript // executeTakeFirst() - Returns first result or undefined const firstPerson = await db.create('person').set({ name: 'Test' }).executeTakeFirst() // Returns: Person | undefined ``` ### `executeTakeFirstOrThrow()` Returns the first result of the query, or throws an error if no results are found. You can provide a custom error class to be thrown. ```typescript // executeTakeFirstOrThrow() - Returns first result or throws NoResultError import {NoResultError} from 'kysely' try { const person = await db .create('person') .set({ name: 'Test' }) .return('none') // This returns empty array .executeTakeFirstOrThrow() } catch (error) { if (error instanceof NoResultError) { console.log('No result returned from query') } } // Custom error class class CustomNotFoundError extends Error { constructor() { super('Person not found') } } const person = await db .selectFrom('person') .where('id', '=', 'person:nonexistent') .selectAll() .executeTakeFirstOrThrow(CustomNotFoundError) ``` ``` -------------------------------- ### Create Records in SurrealDB with Kysely Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Demonstrates creating new records in a SurrealDB table using Kysely's `create()` method. Supports creating records with random IDs, specific string IDs, or numeric IDs. It also shows how to use `set()` for individual fields or `content()` for full object creation. By default, created records are returned. ```typescript const person = await db .create('person') .set({ name: 'Tobie', company: 'SurrealDB', skills: ['Rust', 'Go', 'JavaScript'], }) .executeTakeFirst() // Generated SurrealQL: create person set name = $1, company = $2, skills = $3 ``` ```typescript const specificPerson = await db .create('person:tobie') .set({ name: 'Tobie', company: 'SurrealDB', skills: ['Rust', 'Go', 'JavaScript'], }) .execute() // Result: [{ id: 'person:tobie', name: 'Tobie', company: 'SurrealDB', skills: ['Rust', 'Go', 'JavaScript'] }] ``` ```typescript const numberedPerson = await db .create('person', 100) .set({ name: 'Jennifer', company: 'TechCorp', skills: ['Python'], }) .execute() // Generated SurrealQL: create person:100 set name = $1, company = $2, skills = $3 ``` ```typescript await db .create('person:tobie2') .content({ name: 'Tobie', company: 'SurrealDB', skills: ['Rust', 'Go', 'JavaScript'], }) .return('none') .execute() // Generated SurrealQL: create person:tobie2 content $1 return none ``` -------------------------------- ### Control Return Values for Record Creation in SurrealDB Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Explains how to use the `return()` method with Kysely's `create()` operation to control the data returned after record creation. Options include returning nothing (`none`), changes (`diff`), previous state (`before`), new state (`after`), or specific fields. ```typescript await db .create('person') .set({ age: 46, username: 'john-smith' }) .return('none') .execute() // Generated SurrealQL: create person set age = $1, username = $2 return none // Result: [] ``` ```typescript const diff = await db .create('person') .set({ age: 46, username: 'john-smith' }) .return('diff') .execute() // Generated SurrealQL: create person set age = $1, username = $2 return diff ``` ```typescript const interests = await db .create('person') .set({ age: 46, username: 'john-smith', interests: ['skiing', 'music'], }) .return('interests') .execute() // Result: [{ interests: ['skiing', 'music'] }] ``` ```typescript const partial = await db .create('person') .set({ age: 46, username: 'john-smith', interests: ['skiing', 'music'], }) .return(['name', 'interests']) .execute() // Generated SurrealQL: create person set age = $1, username = $2, interests = $3 return name, interests // Result: [{ interests: ['skiing', 'music'], name: null }] ``` -------------------------------- ### POST /create Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Creates new records in a SurrealDB table using either individual field sets or a full content object. ```APIDOC ## POST /create ### Description Creates new records in a table. You can specify an ID or let the database generate a random one. Supports both partial field updates via `set()` and full object creation via `content()`. ### Method POST ### Endpoint /create/:table/:id? ### Parameters #### Path Parameters - **table** (string) - Required - The name of the table to insert into. - **id** (string/number) - Optional - The specific ID for the record. #### Request Body - **data** (object) - Required - The record fields to be stored. ### Request Example { "name": "Tobie", "company": "SurrealDB", "skills": ["Rust", "Go"] } ### Response #### Success Response (200) - **record** (object) - The created record including its ID. #### Response Example { "id": "person:tobie", "name": "Tobie", "company": "SurrealDB", "skills": ["Rust", "Go"] } ``` -------------------------------- ### Configure Kysely with SurrealDB HTTP Dialect (Node.js) Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Initializes a Kysely instance with the SurrealDbHttpDialect for connecting to SurrealDB via HTTP endpoints. This configuration is suitable for browser environments, serverless functions, and auto-scaling services. It requires connection details like database, hostname, namespace, username, and password. ```typescript import {Kysely} from 'kysely' import {SurrealDatabase, SurrealDbHttpDialect, type SurrealEdge} from 'kysely-surrealdb' import {fetch} from 'undici' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } const db = new Kysely>({ dialect: new SurrealDbHttpDialect({ database: '', fetch, hostname: '', // e.g. 'localhost:8000' namespace: '', password: '', username: '', }), }) ``` -------------------------------- ### Executing Queries with Kysely SurrealDB Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Demonstrates the three primary execution methods for Kysely queries: execute() for full arrays, executeTakeFirst() for optional single records, and executeTakeFirstOrThrow() for strict result enforcement with custom error handling. ```typescript // execute() - Returns array of all results const allPeople = await db.create('person').set({ name: 'Test' }).execute(); // executeTakeFirst() - Returns first result or undefined const firstPerson = await db.create('person').set({ name: 'Test' }).executeTakeFirst(); // executeTakeFirstOrThrow() - Returns first result or throws NoResultError import {NoResultError} from 'kysely'; try { const person = await db .create('person') .set({ name: 'Test' }) .return('none') .executeTakeFirstOrThrow(); } catch (error) { if (error instanceof NoResultError) { console.log('No result returned from query'); } } // Custom error class class CustomNotFoundError extends Error { constructor() { super('Person not found'); } } const person = await db .selectFrom('person') .where('id', '=', 'person:nonexistent') .selectAll() .executeTakeFirstOrThrow(CustomNotFoundError); ``` -------------------------------- ### SurrealKysely Query Builder Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Demonstrates using the SurrealKysely query builder with the HTTP dialect and showcases supported SurrealQL statements. ```APIDOC ### SurrealKysely Query Builder The awesomeness of Kysely, with some SurrealQL query builders patched in. > This example uses `SurrealDbHttpDialect` but `SurrealDbWebSocketsDialect` works just as well. ```ts import {SurrealDbHttpDialect, SurrealKysely, type SurrealEdge} from 'kysely-surrealdb' import {fetch} from 'undici' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } const db = new SurrealKysely({ dialect: new SurrealDbHttpDialect({ database: '', fetch, hostname: '', namespace: '', password: '', username: '', }), }) await db .create('person:100') .set({ first_name: 'Jennifer', age: 15, }) .return('none') .execute() ``` #### Supported SurrealQL specific statements: [create](https://surrealdb.com/docs/surrealql/statements/create), [if else](https://surrealdb.com/docs/surrealql/statements/ifelse), [relate](https://surrealdb.com/docs/surrealql/statements/relate). ``` -------------------------------- ### Configure Kysely with SurrealDB WebSockets Dialect Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Initializes a Kysely instance with the SurrealDbWebSocketsDialect for connecting to SurrealDB via WebSockets. This configuration can use either username/password or a token for authentication. It requires the 'surrealdb.js' package as a peer dependency. ```typescript import {Kysely} from 'kysely' import {SurrealDatabase, SurrealDbWebSocketsDialect, type SurrealEdge} from 'kysely-surrealdb' import Surreal from 'surrealdb.js' interface Database { person: { first_name: string | null last_name: string | null age: number } own: SurrealEdge<{ time: { adopted: string } | null }> pet: { name: string owner_id: string | null } } // with username and password const db = new Kysely>({ dialect: new SurrealDbWebSocketsDialect({ database: '', Driver: Surreal, hostname: '', // e.g. 'localhost:8000' namespace: '', password: '', // scope: '', // optional username: '', }), }) // alternatively, with a token const dbWithToken = new Kysely>({ dialect: new SurrealDbWebSocketsDialect({ database: '', Driver: Surreal, hostname: '', // e.g. 'localhost:8000' namespace: '', token: '', }), }) ``` -------------------------------- ### Deno Import Map for kysely-surrealdb Source: https://github.com/igalklebanov/kysely-surrealdb/blob/main/README.md Configures Deno's import map to resolve Kysely and optional surrealdb.js packages from NPM and a CDN respectively. This is necessary for using Kysely types and the SurrealDbWebSocketsDialect in Deno. ```json { "imports": { "kysely": "npm:kysely@^0.25.0", "surrealdb.js": "https://deno.land/x/surrealdb@v0.5.0" // optional - only if you're using `SurrealDbWebSocketsDialect` } } ``` -------------------------------- ### Extended SurrealQL Query Builder with SurrealKysely Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Demonstrates initializing SurrealKysely, an extended Kysely class that adds SurrealQL-specific query builders like `create`, `relate`, and `ifThen`. This requires the 'kysely-surrealdb' library and can use either HTTP or WebSocket dialects. ```typescript import {SurrealDbHttpDialect, SurrealKysely, type SurrealEdge} from 'kysely-surrealdb' import {fetch} from 'undici' interface Database { person: { name: string company: string skills: string[] } write: SurrealEdge<{ time: { written: string } source: string }> article: { title: string content: string } } const db = new SurrealKysely({ dialect: new SurrealDbHttpDialect({ database: 'test', fetch, hostname: 'localhost:8000', namespace: 'test', password: 'root', username: 'root', }), }) // Now you can use SurrealQL-specific methods // db.create(), db.relate(), db.ifThen() ``` -------------------------------- ### Create Graph Edges in SurrealDB with Kysely Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Illustrates how to create graph relationships (edges) between records in SurrealDB using Kysely's `relate()` method. This requires tables to be defined as `SurrealEdge`. It supports relating specific records, using table and ID arguments separately, relating multiple records to one, and vice versa. It also shows how to use `set()` or `content()` for edge data and control return values. ```typescript import {sql} from 'kysely' // Relate two specific records const relation = await db .relate('write') .from('user:tobie') .to('article:surreal') .set({ 'time.written': sql`time::now()`, }) .executeTakeFirst() // Generated SurrealQL: relate user:tobie->write->article:surreal set time.written = time::now() ``` ```typescript // Relate with table and id as separate arguments await db .relate('write') .from('user', 'tobie') .to('article', 'surrealql') .set({ 'time.written': sql`time::now()` }) .execute() // Generated SurrealQL: relate user:tobie->write->article:surrealql set time.written = time::now() ``` ```typescript // Relate multiple records to one record await db .relate('like') .from(['user:tobie', 'user:igal']) .to('user:moshe') .set({ 'time.connected': sql`time::now()` }) .execute() // Generated SurrealQL: relate [user:tobie, user:igal]->like->user:moshe set time.connected = time::now() ``` ```typescript // Relate one record to multiple records await db .relate('like') .from('user:tobie') .to(['user:moshe', 'user:igal']) .set({ 'time.connected': sql`time::now()` }) .execute() // Generated SurrealQL: relate user:tobie->like->[user:moshe, user:igal] set time.connected = time::now() ``` ```typescript // Relate with content instead of set await db .relate('write') .from('user:tobie') .to('article:surreal') .content(sql`{source: 'Apple notes', tags: ['notes', 'markdown'], time: {written: time::now()}}`) .execute() ``` ```typescript // Relate with return control await db .relate('write') .from('user:tobie') .to('article:surreal') .set({ source: 'Samsung notes', 'time.written': sql`time::now()` }) .return(['source', 'time']) .execute() // Generated SurrealQL: relate user:tobie->write->article:surreal set source = $1, time.written = time::now() return source, time ``` -------------------------------- ### ifThen() - Conditional Logic Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Builds SurrealQL if-else statements for conditional queries, usable both as standalone queries and within other statements. ```APIDOC ## ifThen() - Conditional Logic ### Description Builds SurrealQL if-else statements for conditional queries, usable both as standalone queries and within other statements. ### Method N/A (Query Builder Method) ### Parameters - **condition** (Expression) - Required - The SQL condition to evaluate. - **then** (Expression) - Required - The result if the condition is true. ### Request Example ```typescript db.ifThen(sql`scope = 'admin'`, db.selectFrom('account').selectAll()).end() ``` ``` -------------------------------- ### Implement Conditional Logic with ifThen() Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Builds SurrealQL if-else statements for conditional queries. It supports standalone queries and embedding within update statements to handle dynamic logic. ```typescript import {sql} from 'kysely' const auth = { account: 'account:123' } const scope = 'admin' const result = await db .ifThen( sql`${scope} = ${sql.literal('admin')}`, db.selectFrom('account').selectAll() ) .elseIfThen( sql`${scope} = ${sql.literal('user')}`, sql`(select * from ${auth}.account)` ) .else(sql<[]>`[]`) .end() .execute() ``` -------------------------------- ### POST /relate Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Creates graph relationships (edges) between two records in SurrealDB. ```APIDOC ## POST /relate ### Description Creates a graph edge between a source record and a destination record. Supports one-to-one, one-to-many, and many-to-one relationship mappings. ### Method POST ### Endpoint /relate/:edge_table ### Parameters #### Path Parameters - **edge_table** (string) - Required - The name of the edge table. #### Request Body - **from** (string|array) - Required - The source record ID or array of IDs. - **to** (string|array) - Required - The destination record ID or array of IDs. - **set** (object) - Optional - Fields to set on the edge. ### Request Example { "from": "user:tobie", "to": "article:surreal", "set": { "time.written": "time::now()" } } ### Response #### Success Response (200) - **edge** (object) - The created edge record. #### Response Example { "id": "write:xyz", "in": "user:tobie", "out": "article:surreal", "time": { "written": "2023-10-27T10:00:00Z" } } ``` -------------------------------- ### Define Schema with SurrealDatabase and SurrealEdge Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Type utilities that automatically inject SurrealDB-specific columns like 'id', 'in', and 'out' into schema definitions. This ensures type safety when working with graph edges and record IDs. ```typescript interface Database { person: Person own: SurrealEdge pet: Pet } const db = new SurrealKysely({ dialect: new SurrealDbHttpDialect({ database: 'test', fetch, hostname: 'localhost:8000', namespace: 'test', password: 'root', username: 'root', }), }) ``` -------------------------------- ### SurrealDatabase and SurrealEdge Types Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Type utilities that automatically add SurrealDB-specific columns (id, in, out) to your database schema definitions. ```APIDOC ## SurrealDatabase and SurrealEdge Types ### Description Type utilities that automatically add SurrealDB-specific columns (id, in, out) to your database schema definitions for proper graph edge handling. ### Usage - **SurrealEdge** - Marks a table as a graph edge, automatically adding 'in' and 'out' columns. - **SurrealKysely** - Wrapper for the Kysely instance to handle SurrealDB record ID syntax. ### Example ```typescript interface Database { person: Person own: SurrealEdge } ``` ``` -------------------------------- ### $if() - Conditional Query Building Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Conditionally applies query modifications at runtime while maintaining proper TypeScript types. ```APIDOC ## $if() - Conditional Query Building ### Description Conditionally applies query modifications at runtime while maintaining proper TypeScript types. ### Method N/A (Query Builder Method) ### Parameters - **condition** (boolean) - Required - The condition to evaluate. - **callback** (Function) - Required - A function that modifies the query builder if the condition is true. ### Request Example ```typescript .$if(returnLastName, (qb) => qb.return('last_name')) ``` ``` -------------------------------- ### Apply Conditional Query Modifications with $if() Source: https://context7.com/igalklebanov/kysely-surrealdb/llms.txt Conditionally applies query modifications at runtime. This method allows for dynamic query building while maintaining strict TypeScript type definitions for the result set. ```typescript async function createPerson( values: Insertable, returnLastName: boolean ) { return await db .create('person') .set(values) .return(['id', 'first_name']) .$if(returnLastName, (qb) => qb.return('last_name')) .executeTakeFirstOrThrow() } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.