arangodb
This commit is contained in:
32
src/db.ts
32
src/db.ts
@@ -1,23 +1,17 @@
|
||||
"use server";
|
||||
import { JSONFilePreset } from "lowdb/node";
|
||||
import { GameState, newGame } from "./types/cards";
|
||||
|
||||
type schema = {
|
||||
games: {
|
||||
[key: string]: {
|
||||
name: string;
|
||||
rules: string;
|
||||
instances: { [id: string]: GameState };
|
||||
};
|
||||
};
|
||||
};
|
||||
const _db = await JSONFilePreset<schema>("db.json", {
|
||||
games: {
|
||||
renaissance: {
|
||||
name: "renaissance",
|
||||
rules: "",
|
||||
instances: { test: newGame() },
|
||||
},
|
||||
import { Database } from "arangojs";
|
||||
import { GameState, newGame } from "./types/cards";
|
||||
import { AqlQuery } from "arangojs/aql";
|
||||
|
||||
const db = new Database({
|
||||
url: "http://localhost:8529",
|
||||
auth: {
|
||||
username: "root",
|
||||
password: "pass",
|
||||
},
|
||||
databaseName: "prod",
|
||||
});
|
||||
export const db = async () => _db.read().then(() => _db.data);
|
||||
|
||||
export const query = async <T>(q: AqlQuery<T>) =>
|
||||
await db.query(q).then((c) => c.all());
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { useParams } from "@solidjs/router";
|
||||
import { db } from "../../db";
|
||||
|
||||
import { createEffect, createResource, Show, Suspense } from "solid-js";
|
||||
import Game from "../../components/Game";
|
||||
import { aql } from "arangojs";
|
||||
|
||||
export default () => {
|
||||
const params = useParams();
|
||||
|
||||
const [instance] = createResource(() =>
|
||||
db().then((data) => data.games[params.game].instances[params.instance])
|
||||
);
|
||||
const [instance] = createResource(async () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
return (
|
||||
<Show when={instance() != null}>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { A, useParams } from "@solidjs/router";
|
||||
|
||||
import { createEffect, createResource, For, Suspense } from "solid-js";
|
||||
import { db } from "../../db";
|
||||
import { query } from "../../db";
|
||||
import { aql } from "arangojs";
|
||||
|
||||
export default () => {
|
||||
const params = useParams();
|
||||
@@ -11,22 +12,26 @@ export default () => {
|
||||
const [instances] = createResource(
|
||||
() => params.game,
|
||||
() =>
|
||||
db().then((data) => {
|
||||
if (params.game == null) {
|
||||
return {};
|
||||
}
|
||||
return data.games[params.game].instances;
|
||||
})
|
||||
query<{ _id: string }>(
|
||||
aql`
|
||||
FOR i IN instances
|
||||
FILTER i.name == ${params.game}
|
||||
RETURN i
|
||||
`
|
||||
)
|
||||
);
|
||||
|
||||
createEffect(() => console.log(instances()));
|
||||
|
||||
return (
|
||||
<Suspense>
|
||||
<div style={{ padding: "20px" }}>
|
||||
<h1 style={{ margin: 0 }}>{params.game}</h1>
|
||||
<ul>
|
||||
<For each={Object.entries(instances() ?? {})}>
|
||||
{([instanceId]) => (
|
||||
<A href={`/${params.game}/${instanceId}`}>
|
||||
{instanceId}
|
||||
<For each={instances() ?? []}>
|
||||
{(instance) => (
|
||||
<A href={`/${params.game}/${instance._id}`}>
|
||||
{instance._id}
|
||||
</A>
|
||||
)}
|
||||
</For>
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { A } from "@solidjs/router";
|
||||
import Game from "../components/Game";
|
||||
import { createResource, For } from "solid-js";
|
||||
import { db } from "../db";
|
||||
import { For } from "solid-js";
|
||||
|
||||
export default () => {
|
||||
const [games] = createResource(() => db().then((data) => data.games));
|
||||
const games = [
|
||||
{
|
||||
name: "renaissance",
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div style={{ padding: "20px" }}>
|
||||
<For each={Object.entries(games() ?? {})}>
|
||||
{([gameId, game]) => <A href={`/${gameId}`}>{game.name}</A>}
|
||||
<For each={games}>
|
||||
{(game) => <A href={`/${game.name}`}>{game.name}</A>}
|
||||
</For>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user