Giter Club home page Giter Club logo

kysely-surrealdb's Introduction

๐Ÿ‘‹!

๐Ÿ—บ๏ธ = ๐Ÿ‡ฎ๐Ÿ‡ฑ / ๐Ÿ‡ง๐Ÿ‡พ.

๐Ÿ—ฃ๏ธ = eng, heb, rus.

๐Ÿ’ผ = software engineer (full-time) @grainfinance.

๐Ÿก = ๐Ÿบ + ๐Ÿฑ + ๐Ÿ“บ + ๐ŸŽฎ + ๐Ÿ€ + ๐ŸŽง + ๐Ÿ‹๏ธโ€โ™‚๏ธ.

โค๏ธโ€๐Ÿ”ฅ = typescript, serverless, open-source, bleeding edge (responsibly).


open-source:

trivia:

  • accidentally coined "Tofu", now OpenTofu.

kysely-surrealdb's People

Contributors

igalklebanov avatar naorpeled avatar sonicjhon1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kysely-surrealdb's Issues

Feature: Select queries

Is this feature request related to a problem?

Yes, there is no way to query the database using this library, and the select and selectFrom functions will solve the problem.

Describe the solution

The solution would be to "port" the existing functions from the main kysely.

Alternative methods

Another method would be to implement a raw SQL function allowing the user to insert raw SurrealQL and query it that way.

SurrealDB version

1.3.0+20240222.73a90ac

Is there an existing issue for this?

  • I have searched the existing issues

Is this an abandoned project?

Hello
I would like to know if someone is going to work on this project because if not, I might jump in and do some work. Pull requests can be made?

Is this still active?

This hasn't been updated in 10 months, just want to know if this is being actively maintained?

Support Token authentication with HTTP

Currently the SurrealDbHttpDialect do not support using a token field in the config.

This is an option with the ExperimentalSurrealHTTP

    const db = new ExperimentalSurrealHTTP()
    await db.connect(connectionString,{
        namespace,
        database,
    })


    if (token) db.authenticate(token)

Can't connect to SurrealDB

Hello, its me again :)
For some reason Typescript couldn't call create because for some reason that doesn't exist(?).
Minimal reproduction project here: https://github.com/sonicjhon1/kysely-surreal-error
The code is from the Readme.md example:

await db
	.create('person:100')
	.set({
		first_name: 'Jennifer',
		age: 15,
	})
	.return('none')
	.execute()
> pnpm ts-node index.ts

D:\SJ\Devs\Github\kysely-surreal-error\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: โจฏ Unable to compile TypeScript:
index.ts:29:5 - error TS2339: Property 'create' does not exist on type 'Kysely<SurrealDatabase<Database>>'.

29    .create('person:100')
       ~~~~~~

    at createTSError (D:\SJ\Devs\Github\kysely-surreal-error\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:859:12)
    at reportTSError (D:\SJ\Devs\Github\kysely-surreal-error\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:863:19)
    at getOutput (D:\SJ\Devs\Github\kysely-surreal-error\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:1077:36)
\node_modules\ts-node\src\index.ts:1433:41)
    at Module.m._compile (D:\SJ\Devs\Github\kysely-surreal-error\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Object.require.extensions.<computed> [as .ts] (D:\SJ\Devs\Github\kysely-surreal-error\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Function.Module._load (node:internal/modules/cjs/loader:972:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
  diagnosticCodes: [ 2339 ]
}

Also, the project above doesn't seem to do any connection to the DB even if I modified the code to not use create:

await db.selectFrom("person").selectAll().execute()
$ pnpm ts-node index.ts
> surreal start --log trace --user root --pass root --bind 0.0.0.0:8080 file://D:/SJ/Devs/DB/SurrealDB

2023-05-19T13:42:32.235373Z  INFO surrealdb::env: Running 1.0.0-beta.9+20230402.5eafebd for windows on x86_64
2023-05-19T13:42:32.235497Z  INFO surrealdb::iam: Root authentication is enabled
2023-05-19T13:42:32.235577Z  INFO surrealdb::iam: Root username is 'root'
2023-05-19T13:42:32.235655Z  INFO surrealdb::dbs: Database strict mode is disabled
2023-05-19T13:42:32.235734Z  INFO surrealdb::kvs: Starting kvs store at file://D:/SJ/Devs/DB/SurrealDB
2023-05-19T13:42:32.308941Z  INFO surrealdb::kvs: Started kvs store at file://D:/SJ/Devs/DB/SurrealDB
2023-05-19T13:42:32.309469Z  INFO surrealdb::net: Starting web server on 0.0.0.0:8080
2023-05-19T13:42:32.310541Z  INFO surrealdb::net: Started web server on 0.0.0.0:8080

TypeError: node_js_1.default is not a constructor

I've just tried out using kysely, but for some reason I couldn't get it to work. The database I'm using is SurrealDB, here are the logs from Surreal:

> surreal start --log trace --user root --pass root --bind 0.0.0.0:8080 file://D:/SJ/Devs/DB/SurrealDB

2023-05-19T06:51:40.820002Z  INFO surrealdb::env: Running 1.0.0-beta.9+20230402.5eafebd for windows on x86_64    
2023-05-19T06:51:40.820058Z  INFO surrealdb::iam: Root authentication is enabled    
2023-05-19T06:51:40.820089Z  INFO surrealdb::iam: Root username is 'root'    
2023-05-19T06:51:40.820118Z  INFO surrealdb::dbs: Database strict mode is disabled    
2023-05-19T06:51:40.820208Z  INFO surrealdb::kvs: Starting kvs store at file://D:/SJ/Devs/DB/SurrealDB
2023-05-19T06:51:40.909200Z  INFO surrealdb::kvs: Started kvs store at file://D:/SJ/Devs/DB/SurrealDB
2023-05-19T06:51:40.909557Z  INFO surrealdb::net: Starting web server on 0.0.0.0:8080    
2023-05-19T06:51:40.910596Z  INFO surrealdb::net: Started web server on 0.0.0.0:8080

The Node typescript code:

import * as dotenv from 'dotenv'
dotenv.config()
import { Kysely } from "kysely";
import type { DB } from "./generated/kysely/types";
import { SurrealDatabase, SurrealDbWebSocketsDialect, type SurrealEdge } from "kysely-surrealdb";
import Surreal from "surrealdb.js";

let db: Kysely<SurrealDatabase<DB>> | null = null;

db = new Kysely<SurrealDatabase<DB>>({
	dialect: new SurrealDbWebSocketsDialect({
		Driver: Surreal,
		hostname: process.env.DATABASE_URL || "localhost:8080",
		namespace: process.env.DATABASE_NAMESPACE || "namespace",
		database: process.env.DATABASE_NAME || "name",
		username: process.env.DATABASE_USERNAME || "root",
		password: process.env.DATABASE_PASSWORD || "root",
	}),
});

console.log(await db.selectFrom("Chat").selectAll().execute());

Node just errors out:

$ pnpm ts-node index.ts

D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\library\SurrealSocket.ts:55
                this.ws = new WebSocket(this.url);
            ^
TypeError: node_js_1.default is not a constructor
    at SurrealSocket.open (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\library\SurrealSocket.ts:55:13)
    at WebSocketStrategy.connect (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\strategies\websocket.ts:63:15)
    at SurrealDbWebSocketsConnection.connect (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely-surrealdb@0.7.0_kysely@0.24.2_surrealdb.js@0.7.2\node_modules\kysely-surrealdb\dist\src\dialect\websockets\websockets-connection.ts:32:24)
    at SurrealDbWebSocketsDriver.connect_fn (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely-surrealdb@0.7.0_kysely@0.24.2_surrealdb.js@0.7.2\node_modules\kysely-surrealdb\dist\src\dialect\websockets\websockets-driver.ts:51:60)
    at SurrealDbWebSocketsDriver.acquireConnection (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely-surrealdb@0.7.0_kysely@0.24.2_surrealdb.js@0.7.2\node_modules\kysely-surrealdb\dist\src\dialect\websockets\websockets-driver.ts:19:40)
    at RuntimeDriver.acquireConnection (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\driver\runtime-driver.js:31:47)
    at async DefaultConnectionProvider.provideConnection (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\driver\default-connection-provider.js:10:28)
    at async DefaultQueryExecutor.executeQuery (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\query-executor\query-executor-base.js:36:16)
    at async SelectQueryBuilder.execute (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\kysely@0.24.2\node_modules\kysely\dist\cjs\query-builder\select-query-builder.js:1202:24)
    at async sessionStore.sessionExistsStore [as sessionExists] (D:\SJ\Devs\Github\sonicjhon1.github.io\11 WA-GawrBot\src\wa\store\sessionStore.ts:14:14)
    at async RemoteAuth.extractRemoteSession (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\whatsapp-web.js@1.19.5_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\whatsapp-web.js\src\authStrategies\RemoteAuth.js:119:31)
    at async RemoteAuth.beforeBrowserInitialized (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\whatsapp-web.js@1.19.5_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\whatsapp-web.js\src\authStrategies\RemoteAuth.js:60:9)
    at async Client.initialize (D:\SJ\Devs\Github\sonicjhon1.github.io\node_modules\.pnpm\whatsapp-web.js@1.19.5_bufferutil@4.0.7_utf-8-validate@5.0.10\node_modules\whatsapp-web.js\src\Client.js:88:9)

I have also double-checked that the database is running, I could even connect to the database via Surrealist without any problems.
Screenshot 2023-05-19 153803

Edit: #10 May be related.

Latest SurrealQL Features

Hey,

Great work with this project! is it still under active development? If so, is there an eta for when stuff like if statements, nested clauses and websockets will be supported?

SyntaxError: Unexpected token 'export'

Fails to run kysely-surrealdb on a new project. Minimal reproduction project.

import { Kysely } from "kysely";
import type { DB } from "./src/generated/kysely/types";
import { SurrealDatabase, SurrealDbWebSocketsDialect } from "kysely-surrealdb";
import Surreal from "surrealdb.js";

const db = new Kysely<SurrealDatabase<DB>>({
	dialect: new SurrealDbWebSocketsDialect({
		Driver: Surreal,
		hostname: "localhost:8080",
		namespace: "namespace",
		database: "name",
		username: "root",
		password: "root",
	}),
});

(async function () {
	if (db == null) {
		console.log("db is null");
	} else {
		console.log(await db.selectFrom("Chat").selectAll().execute());
	}
})();

Error:

pnpm run dev

> kysely-surreal@1.0.0 dev D:\SJ\Devs\Github\kysely-surreal
> pnpm dlx prisma generate && ts-node index.ts

../../../../.pnpm-store/v3/tmp/dlx-16396 |   +2 +
../../../../.pnpm-store/v3/tmp/dlx-16396 | Progress: resolved 2, reused 2, downloaded 0, added 2, done
Prisma schema loaded from prisma\schema.prisma

โœ” Generated Kysely types (1.4.1) to .\src\generated\kysely in 12ms

D:\SJ\Devs\Github\kysely-surreal\node_modules\.pnpm\unws@0.2.2_ws@8.13.0\node_modules\unws\src\node.js:3
export { WebSocket }
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1195:20)
    at Module._compile (node:internal/modules/cjs/loader:1239:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Object.require.extensions.<computed> [as .js] (D:\SJ\Devs\Github\kysely-surreal\node_modules\.pnpm\ts-node@10.9.1_@types+node@20.2.1_typescript@5.0.4\node_modules\ts-node\src\index.ts:1608:43)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Function.Module._load (node:internal/modules/cjs/loader:972:12)
    at Module.require (node:internal/modules/cjs/loader:1157:19)
    at require (node:internal/modules/helpers:119:18)
    at Object.<anonymous> (D:\SJ\Devs\Github\kysely-surreal\node_modules\.pnpm\surrealdb.js@0.7.2_ws@8.13.0\node_modules\surrealdb.js\src\library\WebSocket\node.ts:2:1)
โ€‰ELIFECYCLEโ€‰ Command failed with exit code 1.

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.