Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
kysely-surrealdb
Advanced tools
Kysely dialects, plugins and other goodies for SurrealDB.
SurrealQL is based on SQL, so why not? :trollface:
npm i kysely-surrealdb
npm i kysely-surrealdb kysely surrealdb.js
yarn add kysely-surrealdb kysely surrealdb.js
pnpm add kysely-surrealdb kysely surrealdb.js
surrealdb.js
is an optional peer dependency. It's only needed if you want to useSurrealDbWebSocketsDialect
. If you don't need it, you can removesurreal.js
from the install commands above.
This package uses/extends some 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
file.
{
"imports": {
"kysely": "https://cdn.jsdelivr.net/npm/kysely@0.23.5/dist/esm/index.js",
"surrealdb.js": "https://deno.land/x/surrealdb@v0.5.0" // optional - only if you're using `SurrealDbWebSocketsDialect`
}
}
SurrealDB's HTTP endpoints allow executing SurrealQL queries in the browser and are a great fit for serverless functions and other auto-scaling compute services.
Older node versions are supported as well, just swap undici
with node-fetch
.
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<SurrealDatabase<Database>>({
dialect: new SurrealDbHttpDialect({
database: '<database>',
fetch,
hostname: '<hostname>', // e.g. 'localhost:8000'
namespace: '<namespace>',
password: '<password>',
username: '<username>',
}),
})
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<SurrealDatabase<Database>>({
dialect: new SurrealDbWebSocketsDialect({
database: '<database>',
Driver: Surreal,
hostname: '<hostname>', // e.g. 'localhost:8000'
namespace: '<namespace>',
password: '<password>',
// scope: '<scope>', // optional
username: '<username>',
}),
})
// alternatively, with a token
const dbWithToken = new Kysely<SurrealDatabase<Database>>({
dialect: new SurrealDbWebSocketsDialect({
database: '<database>',
Driver: Surreal,
hostname: '<hostname>', // e.g. 'localhost:8000'
namespace: '<namespace>',
token: '<token>',
}),
})
The awesomeness of Kysely, with some SurrealQL query builders patched in.
This example uses
SurrealDbHttpDialect
butSurrealDbWebSocketsDialect
works just as well.
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<Database>({
dialect: new SurrealDbHttpDialect({
database: '<database>',
fetch,
hostname: '<hostname>',
namespace: '<namespace>',
password: '<password>',
username: '<username>',
}),
})
await db
.create('person:100')
.set({
first_name: 'Jennifer',
age: 15,
})
.return('none')
.execute()
Kysely is growing to be THE sql query builder solution in the typescript ecosystem. Koskimas' dedication, attention to detail, experience from creating objection.js, project structure, simplicity, design patterns and philosophy, made adding code to that project a really good experience as a contributor. Taking what's great about that codebase, and patching in SurrealQL stuff seems like an easy win in the short-medium term.
MIT License, see LICENSE
FAQs
Kysely dialects, plugins and other goodies for SurrealDB
The npm package kysely-surrealdb receives a total of 22 weekly downloads. As such, kysely-surrealdb popularity was classified as not popular.
We found that kysely-surrealdb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.