Skip to content

Commit 6ed7e1e

Browse files
committed
0.1.23 make uniqueid required prop
1 parent d27dba3 commit 6ed7e1e

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "@netron/surreal",
3-
"version": "0.1.22",
3+
"version": "0.1.23",
44
"exports": "./index.ts"
55
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netron/surreal",
3-
"version": "0.1.22",
3+
"version": "0.1.23",
44
"description": "type safe surrealdb",
55
"main": "index.ts",
66
"scripts": {

src/NSurreal.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ export class NSurreal<G extends Record<string, object> = {}> {
1212
timestamp_connected: Date | undefined;
1313
url: string | undefined;
1414
opts: ConnectionOptions | undefined;
15-
1615
output_path: string = "./src/generated";
1716

18-
constructor(options?: { output_path: string }) {
17+
debug = false;
18+
19+
constructor(options?: { output_path: string; debug?: boolean }) {
1920
if (options?.output_path) {
2021
this.output_path = options.output_path;
2122
}
2223

24+
if (options?.debug) {
25+
this.debug = options.debug;
26+
}
27+
2328
this.client = new Surreal();
2429
this.timer = setInterval(() => {
2530
if (!this.timestamp_connected) return;
@@ -36,11 +41,21 @@ export class NSurreal<G extends Record<string, object> = {}> {
3641
/** Connects to a local or remote database endpoint.
3742
* https://surrealdb.com/docs/surrealdb/integration/sdks/javascript#connect
3843
*/
44+
45+
log(...input: any[]) {
46+
if (this.debug) console.log(`NSurreal -`, input);
47+
}
48+
3949
async connect(url: string, opts?: ConnectionOptions): Promise<void> {
40-
if (!this.client) throw new Error("Client not connected");
50+
this.log(`Connecting to ${url}`);
51+
if (!this.client) {
52+
this.log(`Client not connected`);
53+
throw new Error("Client not connected");
54+
}
4155
this.opts = opts;
4256
this.url = url;
4357
await this.client.connect(url, opts);
58+
this.log("Connected!");
4459
this.timestamp_connected = new Date();
4560
}
4661

@@ -69,8 +84,9 @@ export class NSurreal<G extends Record<string, object> = {}> {
6984
async query<Q extends keyof G>(
7085
query: string,
7186
/** we create a unique tag for this query to link the output back to the type */
72-
uniqueID?: Q
87+
uniqueID: Q
7388
): Promise<G[Q]> {
89+
this.log("Querying", query, uniqueID);
7490
query = query.trim();
7591
if (!this.client) throw new Error("Client not connected");
7692

src/surreal_helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from "zod";
33
import { NSurreal } from "./NSurreal";
44

55
export async function SR_getInfoForKV({ db }: { db: NSurreal<any> }) {
6-
const result = await db.query("INFO FOR KV;").catch((err) => {
6+
const result = await db.query("INFO FOR KV;", "info for kv").catch((err) => {
77
console.log(err);
88
});
99

@@ -21,7 +21,7 @@ export async function SR_getInfoForKV({ db }: { db: NSurreal<any> }) {
2121
}
2222

2323
export async function SR_getInfoForNS({ db }: { db: NSurreal<any> }) {
24-
const result = await db.query("INFO FOR NS;").catch((err) => {
24+
const result = await db.query("INFO FOR NS;", "info for ns").catch((err) => {
2525
console.log(err);
2626
});
2727

@@ -98,7 +98,7 @@ export async function SR_derive_fields_from_table({
9898
table: string;
9999
}) {
100100
const result = await db
101-
.query(`SELECT * FROM ${table} LIMIT 10;`)
101+
.query(`SELECT * FROM ${table} LIMIT 10;`, "derive_fields_from_table")
102102
.catch((err) => {
103103
console.log(err);
104104
});

0 commit comments

Comments
 (0)