-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user to D1 sample endpoint
- Loading branch information
Showing
1 changed file
with
14 additions
and
3 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 |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import { Hono } from 'hono' | ||
import { drizzle } from 'drizzle-orm/d1'; | ||
import { Env } from './types/drizzleTypes'; | ||
import { users } from './db/schema'; | ||
|
||
const app = new Hono() | ||
const app = new Hono<{ Bindings: Env}>() | ||
|
||
app.get('/', (c) => { | ||
return c.text('Hello Hono!') | ||
app.get('/', async (c) => { | ||
const db = drizzle(c.env.DB) | ||
|
||
await db.insert(users).values({ | ||
name: 'Eric', | ||
}) | ||
|
||
const dbUsers = await db.select().from(users) | ||
|
||
return c.json(dbUsers[0]) | ||
}) | ||
|
||
export default app |