done with upgrades..... I believe
This commit is contained in:
@@ -1,36 +1,32 @@
|
||||
import Surreal from "surrealdb.js";
|
||||
export type { QueryResult } from "surrealdb.js/script/types";
|
||||
import Surreal, { RecordId, StringRecordId } from "surrealdb";
|
||||
export type { QueryResult } from "surrealdb";
|
||||
|
||||
try {
|
||||
if (document || window) {
|
||||
throw new Error("SurrealDB needs a NodeJS environment to run.");
|
||||
}
|
||||
if (document || window) {
|
||||
throw new Error("SurrealDB needs a NodeJS environment to run.");
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
const CONFIG = {
|
||||
url: process.env.SURREAL_URL ?? "",
|
||||
user: process.env.SURREAL_USER ?? "",
|
||||
pass: process.env.SURREAL_PASS ?? "",
|
||||
ns: process.env.SURREAL_NS ?? "",
|
||||
db: process.env.SURREAL_DB ?? "",
|
||||
url: process.env.SURREAL_URL ?? "",
|
||||
user: process.env.SURREAL_USER ?? "",
|
||||
pass: process.env.SURREAL_PASS ?? "",
|
||||
ns: process.env.SURREAL_NS ?? "",
|
||||
db: process.env.SURREAL_DB ?? "",
|
||||
} as const;
|
||||
|
||||
// for (let key in CONFIG) {
|
||||
// if (
|
||||
// !CONFIG[key as keyof typeof CONFIG] ||
|
||||
// CONFIG[key as keyof typeof CONFIG] === ""
|
||||
// ) {
|
||||
// throw new Error(`Missing configuration for ${key}`);
|
||||
// }
|
||||
// }
|
||||
const db = new Surreal();
|
||||
|
||||
let _surreal =
|
||||
CONFIG.url.length > 0
|
||||
? new Surreal(`http://${CONFIG.url}/rpc`, {
|
||||
auth: { user: CONFIG.user, pass: CONFIG.pass },
|
||||
ns: CONFIG.ns,
|
||||
db: CONFIG.db,
|
||||
})
|
||||
: undefined;
|
||||
export function parseToRID(idStr: string) {
|
||||
return new StringRecordId(idStr);
|
||||
// const [a, b] = idStr.split(":");
|
||||
// return new RecordId(a, b);
|
||||
}
|
||||
|
||||
export const surreal = _surreal as Surreal;
|
||||
if (CONFIG.url.length > 0) {
|
||||
await db.connect(`http://${CONFIG.url}/rpc`);
|
||||
await db.use({ namespace: CONFIG.ns, database: CONFIG.db });
|
||||
await db.signin({ username: CONFIG.user, password: CONFIG.pass });
|
||||
}
|
||||
|
||||
export const surreal = db as Surreal;
|
||||
|
||||
Reference in New Issue
Block a user