Conversation
surrealdb.ts
Outdated
|
|
||
| // Small changes associated with the naming rules: | ||
| // - replacement "-" on "_" in the name of the base, | ||
| // - replacement ":" on "_" in the identifier. |
There was a problem hiding this comment.
yes, without it we go into exception. The base ID has the syntax {table_name}:{id}. And the hyphen in the table name indicates that this is not a table, but an object
surrealdb.ts
Outdated
| client = new Surreal.default(`${opts.url}/rpc`); | ||
| client.signin(opts.auth!) | ||
| .then(async () => { | ||
| await client.use(opts.namespace!, opts.database!); |
There was a problem hiding this comment.
Nitpick: unnecessary async await:
| await client.use(opts.namespace!, opts.database!); | |
| .then(() => client.use(opts.namespace, opts.database)) |
surrealdb.ts
Outdated
| client = new Surreal.default(`${opts.url}/rpc`); | ||
| client.signin(opts.auth!) | ||
| .then(async () => { | ||
| await client.use(opts.namespace!, opts.database!); |
There was a problem hiding this comment.
Provide the defaults here.
client.use(opts.namespace ?? <default>, opts.database ?? <default>))Don't use ! assertions unless you know something TS doesn't.
surrealdb.ts
Outdated
|
|
||
| return { | ||
| async get(key) { | ||
| await client.wait(); |
There was a problem hiding this comment.
Move client.wait() before return and assign it to a variable. Then await that variable here. Also errors should be caught and passed to opts.onInitError:
const conn = client.wait();
conn.catch(opts.onInitError);I understand the Redis adapter is missing this as well; I'll fix it. Meanwhile, refer to the MongoDB adapter.
| const resp = await client.query(`SELECT * FROM ${surrealDefaultTable} WHERE id=${surrealId(key)}`); | ||
| const result: TSurrealRecord[] = resp[0].result as TSurrealRecord[]; | ||
| if (result.length === 0) return undefined; | ||
| return result[0].value; |
There was a problem hiding this comment.
Do JSON documents just work in SurrealDB? No need for parsing?
Fixes #1
SurrealDB adapter for telegraf/session