Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Finder (MacOS) folder config
.DS_Store
*.sqlite
.direnv/
2 changes: 2 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ bun --hot ./index.ts
```

For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.

## Learning about "effect"

The source code is available at `.repos/effect`

Use this instead of node_modules
57 changes: 57 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,36 @@ db.exec(`
`);

export function saveRound(round: RoundState) {
const insert = db.prepare("INSERT INTO rounds (num, data) VALUES ($num, $data)");
const insert = db.prepare(
"INSERT INTO rounds (num, data) VALUES ($num, $data)",
);
insert.run({ $num: round.num, $data: JSON.stringify(round) });
}

export function getRounds(page: number = 1, limit: number = 10) {
const offset = (page - 1) * limit;
const countQuery = db.query("SELECT COUNT(*) as count FROM rounds").get() as { count: number };
const rows = db.query("SELECT data FROM rounds ORDER BY num DESC, id DESC LIMIT $limit OFFSET $offset")
const countQuery = db.query("SELECT COUNT(*) as count FROM rounds").get() as {
count: number;
};
const rows = db
.query(
"SELECT data FROM rounds ORDER BY num DESC, id DESC LIMIT $limit OFFSET $offset",
)
.all({ $limit: limit, $offset: offset }) as { data: string }[];
return {
rounds: rows.map(r => JSON.parse(r.data) as RoundState),
rounds: rows.map((r) => JSON.parse(r.data) as RoundState),
total: countQuery.count,
page,
limit,
totalPages: Math.ceil(countQuery.count / limit)
totalPages: Math.ceil(countQuery.count / limit),
};
}

export function getAllRounds() {
const rows = db.query("SELECT data FROM rounds ORDER BY num ASC, id ASC").all() as { data: string }[];
return rows.map(r => JSON.parse(r.data) as RoundState);
const rows = db
.query("SELECT data FROM rounds ORDER BY num ASC, id ASC")
.all() as { data: string }[];
return rows.map((r) => JSON.parse(r.data) as RoundState);
}

export function clearAllRounds() {
Expand Down
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
outputs = {nixpkgs, ...}: let
forAllSystems = function:
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: function nixpkgs.legacyPackages.${system}
);
in {
formatter = forAllSystems (pkgs: pkgs.alejandra);
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
bun
corepack
nodejs
];
};
});
};
}
Loading