-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9b4ebd9
Showing
12 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# deps | ||
node_modules/ | ||
sqlite.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "hono/jsx" | ||
} | ||
} |