Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

SurrealDB adapter #2

wants to merge 3 commits into from

Conversation

jjazzme
Copy link

@jjazzme jjazzme commented Mar 6, 2023

Fixes #1

SurrealDB adapter for telegraf/session

surrealdb.ts Outdated

// Small changes associated with the naming rules:
// - replacement "-" on "_" in the name of the base,
// - replacement ":" on "_" in the identifier.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these required?

Copy link
Author

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!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: unnecessary async await:

Suggested change
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!);
Copy link
Member

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();
Copy link
Member

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;
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, no need

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very promising base

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

need for SurrealDB connector for SESSION
2 participants