-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SurrealDB adapter #2
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do JSON documents just work in SurrealDB? No need for parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, no need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very promising base
Fixes #1
SurrealDB adapter for telegraf/session