This commit is contained in:
2025-08-05 00:26:05 -04:00
parent 5527506cb9
commit 5fd0df8135
8 changed files with 203 additions and 116 deletions

43
sync_db.ts Normal file
View File

@@ -0,0 +1,43 @@
import { Database, aql } from "arangojs";
import { DocumentCollection, SchemaOptions } from "arangojs/collections";
import { EnsurePersistentIndexOptions } from "arangojs/indexes";
import { JSONSchema7 } from "json-schema";
// It's good practice to specify the URL.
// We connect to the _system database first to check if our target DB exists.
const sysdb = new Database({
url: "http://localhost:8529",
auth: {
username: "root",
password: "pass",
},
});
const db = sysdb.database("prod");
const ent = async (
name: string,
schema?: SchemaOptions,
index?: EnsurePersistentIndexOptions
) => {
const col = db.collection(name);
// @ts-ignore
await col.exists().then((e) => e || db.createCollection(name));
schema && col.properties({ schema });
index && col.ensureIndex(index);
return col;
};
const Games = ent("games", {
rule: {
type: "object",
properties: {
name: { type: "string" },
},
} as JSONSchema7,
});
const Instances = ent("instances");
const Humans = ent("humans");