Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jiabochao committed May 30, 2024
0 parents commit 9b4ebd9
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# deps
node_modules/
sqlite.db
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To install dependencies:
```sh
bun install
```

To run:
```sh
bun run dev
```

open http://localhost:3000
Binary file added bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "drizzle-kit";

export default defineConfig({
dialect: "sqlite",
schema: "./src/schema.ts",
out: "./drizzle",
});
5 changes: 5 additions & 0 deletions drizzle/0000_sloppy_sleepwalker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE `movies` (
`id` integer PRIMARY KEY NOT NULL,
`name` text,
`release_year` integer
);
44 changes: 44 additions & 0 deletions drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"version": "6",
"dialect": "sqlite",
"id": "fff260c7-fc4d-4c38-b791-97a8ef44f69e",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"movies": {
"name": "movies",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"release_year": {
"name": "release_year",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
13 changes: 13 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "6",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "6",
"when": 1717081392168,
"tag": "0000_sloppy_sleepwalker",
"breakpoints": true
}
]
}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"scripts": {
"dev": "bun run --hot src/index.ts"
},
"dependencies": {
"drizzle-orm": "^0.30.10",
"hono": "^4.4.0"
},
"devDependencies": {
"@types/bun": "latest",
"drizzle-kit": "^0.21.4"
}
}
5 changes: 5 additions & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { drizzle } from "drizzle-orm/bun-sqlite";
import { Database } from "bun:sqlite";

const sqlite = new Database("sqlite.db");
export const db = drizzle(sqlite);
40 changes: 40 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Hono } from "hono";
import { db } from "./db";
import { sql } from "drizzle-orm";
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
import * as schema from "./schema";

migrate(db, { migrationsFolder: "drizzle" });

const app = new Hono();

app.get("/", (c) => {
const query = sql`select "hello world" as text`;
const result = db.get<{ text: string }>(query);
return c.json(result);
});

app.get("/insert", async (c) => {
await db.insert(schema.movies).values([
{
title: "The Matrix",
releaseYear: 1999,
},
{
title: "The Matrix Reloaded",
releaseYear: 2003,
},
{
title: "The Matrix Revolutions",
releaseYear: 2003,
},
]);
return c.text("ok");
});

app.get("/list", async (c) => {
const result = await db.select().from(schema.movies);
return c.json(result);
});

export default app;
7 changes: 7 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";

export const movies = sqliteTable("movies", {
id: integer("id").primaryKey(),
title: text("name"),
releaseYear: integer("release_year"),
});
7 changes: 7 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"strict": true,
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
}
}

0 comments on commit 9b4ebd9

Please sign in to comment.