6 createMessage,
7 getUserById
8} from "../database/queries.ts";
9import { ApiResponse, ChatRoom, Message, MessageInput } from "../../shared/types.ts";
10
5 getOpportunitiesByCategory,
6 getUserById
7} from "../database/queries.ts";
8import { ApiResponse, Opportunity, OpportunityInput } from "../../shared/types.ts";
9
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { createUser, getUserByUsername } from "../database/queries.ts";
3import { ApiResponse, User } from "../../shared/types.ts";
4
1# Database Layer
2
3This directory contains the database schema and query functions for the Side Hustle Hub application.
4
5## Files
6
7- `migrations.ts`: Contains the database schema definitions and initial setup
8- `queries.ts`: Contains typed query functions for interacting with the database
9
10## Database Schema
11
12The application uses SQLite with the following tables:
19## Usage
20
21The database is initialized when the application starts by calling `runMigrations()` from the main backend entry point.
22
23Query functions are exported from `queries.ts` and provide typed access to the database.
2import { cors } from "https://esm.sh/hono@3.11.7/middleware";
3import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
4import { setupDatabase } from "./database/migrations.ts";
5import {
6 createUser,
11 assignTransactionToEnvelope,
12 checkFullAllocation
13} from "./database/queries.ts";
14import { parseCSV } from "./parsers/csv-parser.ts";
15import type { CSVMapping } from "../shared/types.ts";
25app.use("/*", cors());
26
27// Initialize database on startup
28app.use("*", async (c, next) => {
29 await setupDatabase();
30 await next();
31});
7export const ACHIEVEMENTS_TABLE = "cash_stash_achievements";
8
9export async function setupDatabase() {
10 // Create users table
11 await sqlite.execute(`
25```
26โโโ backend/
27โ โโโ database/ # SQLite database setup and queries
28โ โโโ parsers/ # CSV parsing logic
29โ โโโ index.ts # Main API entry point
9- The **client-side entrypoint** is `/frontend/index.html`, which in turn imports `/frontend/index.tsx`, which in turn imports the React app from `/frontend/components/App.tsx`.
10
11[React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a fuller featured example project, with a SQLite database table, queries, client-side CSS and a favicon, and some shared code that runs on both client and server.
8 CreateProductPayload, // Added import
9} from "../../shared/types.ts"
10import * as db from "../database/queries.ts"
11import {aiServiceInstance} from "./aiService.ts"
12import {logUserAction} from "./userService.ts"
36 await blob.set(blobId, ia)
37
38 // Create a preliminary bill record in the database
39 const scanDate = new Date().toISOString()
40 const partialBill = await db.createSupplierBill(blobId, scanDate, userId)
5 CreateCategoryPayload,
6} from "../../shared/types.ts";
7import * as db from "../database/queries.ts";
8import { logUserAction } from "./userService.ts"; // For logging actions
9