37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
|
|
import { Client } from "memjs";
|
||
|
|
import { effects, types, weapons, armors, shields, talismans, items, regions, enemies } from "../../data";
|
||
|
|
const memcached = Client.create("localhost:41211");
|
||
|
|
|
||
|
|
console.log("Populating database with ~100 static Ringstats entries...");
|
||
|
|
|
||
|
|
const setJson = async (key: string, value: any) => {
|
||
|
|
await memcached.set(key, JSON.stringify(value), {});
|
||
|
|
};
|
||
|
|
|
||
|
|
const setEntities = async (prefix: string, list: any[]) => {
|
||
|
|
for (const obj of list) {
|
||
|
|
const { items, enemies, ...data } = obj;
|
||
|
|
await setJson(`${prefix}:${obj.id}`, data);
|
||
|
|
if (items && items.length > 0) {
|
||
|
|
await setJson(`${prefix}:${obj.id}:items`, items);
|
||
|
|
}
|
||
|
|
if (enemies && enemies.length > 0) {
|
||
|
|
await setJson(`${prefix}:${obj.id}:enemies`, enemies);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
await setEntities("item_effect", effects);
|
||
|
|
await setEntities("item_type", types);
|
||
|
|
await setEntities("weapon", weapons);
|
||
|
|
await setEntities("armor", armors);
|
||
|
|
await setEntities("shield", shields);
|
||
|
|
await setEntities("talisman", talismans);
|
||
|
|
await setEntities("item", items);
|
||
|
|
await setEntities("region", regions);
|
||
|
|
await setEntities("enemy", enemies);
|
||
|
|
|
||
|
|
console.log(`Inserted ${effects.length + types.length + weapons.length + armors.length + shields.length + talismans.length + items.length + regions.length + enemies.length} primary entities into Memcached.`);
|
||
|
|
console.log("Database successfully seeded.");
|
||
|
|
process.exit(0);
|