Coder Social home page Coder Social logo

naorpeled / kysely-surrealdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from igalklebanov/kysely-surrealdb

0.0 0.0 0.0 109 KB

Kysely dialects, plugins and other goodies for SurrealDB

License: MIT License

JavaScript 5.16% TypeScript 94.84%

kysely-surrealdb's Introduction

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 it's 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/[email protected]/dist/esm/index.js"
  }
}

Usage

HTTP Dialect

SurrealDB's HTTP endpoints allows executing SurrealQL queries in the browser and is 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()

License

MIT License, see LICENSE

kysely-surrealdb's People

Contributors

igalklebanov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.