Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions hono-drizzle-postgres/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf

# deps
node_modules/

# env
.env
.env.production

# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store
69 changes: 69 additions & 0 deletions hono-drizzle-postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Hono - Drizzle - Postgres Sample Todo Example

This is a simple Todo application built using **Hono**, **Drizzle**, **PostgreSQL**, **JWT**, and **TypeScript**.

## Features

- User authentication with JWT
- CRUD operations for Todo items
- Drizzle ORM for fast and efficient database operations

## Tech Stack

- **Framework**: Hono
- **Database**: PostgreSQL
- **ORM**: Drizzle
- **Authentication**: JWT
- **Language**: TypeScript
- **Package Manager**: NPM

## API Endpoints

The application includes the following API routes:

### Public Routes

- POST /auth/register - Register a new user
- POST /auth/login - Log in a user
- POST /auth/logout - Log out a user

### Protected Routes (require authentication)

- POST /todo/add-todo - Create a new todo
- GET /todo/get-todos - Get all todos of a user
- PUT /todo/toggle-todo-status - Toggle a todo status
- DELETE /todo/delete-todo - Delete a todo



## Setup Instructions


1. **Install dependencies**:
```sh
npm install
```

2. **Set up the database**:
Ensure you have PostgreSQL installed and running. Create a new database and update the database connection settings in the `.env` file.


3. **Generate Drizzle models**:
```sh
npx run db:generate
```


4. **Run database migrations**:
```sh
npx run db:migrate
```

5. **Start the application**:
```sh
npm run dev
```


### Note:
Scripts like `db:generate` and `db:migrate` are defined in the `package.json` file already for your convenience. You can run them using `npm run <script-name>` as shown above.
21 changes: 21 additions & 0 deletions hono-drizzle-postgres/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { config } from 'dotenv';
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';


config(
{
path: './.env',
}
)

export default defineConfig({
schema: './src/drizzle/schema.ts',
out: './src/drizzle/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
verbose: true,
strict: true,
});
7 changes: 7 additions & 0 deletions hono-drizzle-postgres/drizzle/0000_wise_sunspot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE "users" (
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"name" varchar(255) NOT NULL,
"password" varchar(255) NOT NULL,
"email" varchar(255) NOT NULL,
CONSTRAINT "users_email_unique" UNIQUE("email")
);
75 changes: 75 additions & 0 deletions hono-drizzle-postgres/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"id": "930b20b0-4719-4ad1-861e-c7509e295b1a",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"identity": {
"type": "always",
"name": "users_id_seq",
"schema": "public",
"increment": "1",
"startWith": "1",
"minValue": "1",
"maxValue": "2147483647",
"cache": "1",
"cycle": false
}
},
"name": {
"name": "name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"password": {
"name": "password",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions hono-drizzle-postgres/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1738220820408,
"tag": "0000_wise_sunspot",
"breakpoints": true
}
]
}
Loading