Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kysely-surrealdb

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kysely-surrealdb

Kysely dialects, plugins and other goodies for SurrealDB

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
Maintainers
1
Weekly downloads
 
Created
Source

kysely-surrealdb

Powered by TypeScript

Kysely dialects, plugins and other goodies for SurrealDB.

SurrealQL is based on SQL, so why not? :trollface:

Installation

NPM 7+
npm i kysely-surrealdb
NPM <7
npm i kysely-surrealdb kysely
Yarn
yarn add kysely-surrealdb kysely
PNPM
pnpm add kysely-surrealdb kysely

Deno

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.

To fix that, add an import_map.json file.

{
  "imports": {
    "kysely": "https://cdn.jsdelivr.net/npm/kysely@0.22.0/dist/esm/index.js"
  }
}

Usage

HTTP Dialect

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.

Node.js 16.8+

Older node versions are supported as well, just swap undici with node-fetch.

import {GeneratedAlways, Kysely} from 'kysely'
import {SurrealDatabase, SurrealDbHttpDialect} from 'kysely-surrealdb'
import {fetch} from 'undici'

interface Database {
  person: {
    id: GeneratedAlways<string>
    first_name: string | null
    last_name: string | null
    age: number
  }
  pet: {
    id: GeneratedAlways<string>
    name: string
    owner_id: string | null
  }
}

const db = new Kysely<SurrealDatabase<Database>>({
  dialect: new SurrealDbHttpDialect({
    database: '<database>',
    fetch,
    hostname: '<hostname>',
    namespace: '<namespace>',
    password: '<password>',
    username: '<username>',
  }),
})

Web Socket Dialect - SoonTM

SurrealKysely Query Builder

The awesomeness of Kysely, with some SurrealQL query builders patched in.

import {GeneratedAlways, Kysely} from 'kysely'
import {SurrealDbHttpDialect, SurrealKysely} from 'kysely-surrealdb'
import {fetch} from 'undici'

interface Database {
  person: {
    id: GeneratedAlways<string>
    first_name: string | null
    last_name: string | null
    age: number
  }
  pet: {
    id: GeneratedAlways<string>
    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()
Why not write a query builder from scratch

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.

License

MIT License, see LICENSE

Keywords

FAQs

Package last updated on 17 Oct 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc