1import { Hono } from "npm:hono";
2import { getCreditBalance, getUser } from "../database/queries.tsx";
3
4const app = new Hono();
1// @val-town anchorAPI
2// Main HTTP API handler for Anchor AppView
3import { db, initializeTables } from "../database/db.ts";
4import {
5 checkinsTable,
6 processingLogTable,
7 userFollowsTable,
8} from "../database/schema.ts";
9import { and, desc, eq, inArray, lt, sql } from "https://esm.sh/drizzle-orm";
10import { ATProtocolProfileResolver } from "../utils/profile-resolver.ts";
18import { PlacesNearbyResponse } from "../models/place-models.ts";
19import { createCheckin } from "./checkins.ts";
20import { getCheckinCounts, getRecentActivity } from "../database/queries.ts";
21
22// Types for better TypeScript support
69 }
70
71 // Initialize database tables - let errors bubble up
72 await initializeTables();
73
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257 ```
258
259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
29
30- [React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a
31 bigger example project, with a SQLite database table, queries, client-side
32 CSS, a favicon, and shared code that runs on both client and server.
29
30- [React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a
31 bigger example project, with a SQLite database table, queries, client-side
32 CSS, a favicon, and shared code that runs on both client and server.
4import type { Place } from "../models/place-models.ts";
5import { processCheckinEvent as _processCheckinEvent } from "../ingestion/record-processor.ts";
6import { db } from "../database/db.ts";
7import { checkinsTable } from "../database/schema.ts";
8import { eq } from "https://esm.sh/drizzle-orm";
9
441 console.log(`โ
Created checkin record: ${checkinResult.uri}`);
442
443 // IMMEDIATELY save to local database for instant feed updates
444 try {
445 const rkey = extractRkey(checkinResult.uri);
455 },
456 });
457 console.log(`โ
Saved checkin to local database: ${rkey}`);
458 } catch (localSaveError) {
459 console.error(
460 "Failed to save checkin to local database:",
461 localSaveError,
462 );
648// console.log(`โ
Created checkin record: ${checkinResult.uri}`);
649//
650// // IMMEDIATELY save to local database for instant feed updates
651// try {
652// const rkey = extractRkey(checkinResult.uri);
662// },
663// });
664// console.log(`โ
Saved checkin to local database: ${rkey}`);
665// } catch (localSaveError) {
666// console.error(
667// "Failed to save checkin to local database:",
668// localSaveError,
669// );
4
5import { DrizzleStorage } from "jsr:@tijs/atproto-oauth-hono@^0.2.3/drizzle";
6import { db } from "../database/db.ts";
7
8// Create singleton instance using Drizzle storage with our database
9export const storage = new DrizzleStorage(db);
10
2// Main HTTP entry point for Anchor AppView - organized route groups
3import { Hono } from "jsr:@hono/hono@4.9.6";
4import { initializeTables } from "./backend/database/db.ts";
5import { oauthRoutes } from "./backend/routes/oauth.ts";
6import { createAdminRoutes } from "./backend/routes/admin.ts";
11const app = new Hono();
12
13// Initialize database on startup
14await initializeTables();
15
15
16 try {
17 // Simple GET endpoint to test database
18 if (req.method === "GET") {
19 const result = await sqlite.execute("SELECT datetime() as current_time");
21 JSON.stringify({
22 success: true,
23 message: "Database connection works!",
24 time: result.rows[0],
25 }),
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257 ```
258
259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering