An open API service indexing awesome lists of open source software.

https://github.com/mhdzhhan/bun-basket

๐ŸŽฏ Zero ORM, SQL experiments with Bun + PostgreSQL
https://github.com/mhdzhhan/bun-basket

bun bun-sql express neon postgresql

Last synced: 11 months ago
JSON representation

๐ŸŽฏ Zero ORM, SQL experiments with Bun + PostgreSQL

Awesome Lists containing this project

README

          

# ๐Ÿ›๏ธ Bun Basket

A lightweight, secure, and scalable REST API for managing products, built with **Express**, **TypeScript**, and **Bun**. It includes a powerful migration script, input validation, and structured logging out of the box.

## ๐Ÿš€ Features

- ๐Ÿงฑ Type-safe environment config using Zod
- ๐Ÿ” Security with Helmet
- ๐Ÿงพ Structured logging via Pino
- โœ… Request validation with Zod schemas
- โšก Ultra-lightweight SQL queries using `bun-sql`
- ๐Ÿ“ฆ Products CRUD API
- ๐Ÿง™โ€โ™‚๏ธ Superpowered `migrate.ts` for handling database migrations (with advisory locks!)

## ๐Ÿ”ง Setup

1. **Clone the repo**

```bash
git clone https://github.com/mhdZhHan/bun-basket
cd bun-basket
```

2. **Install dependencies**

```bash
bun install
```

3. **Set up environment variables**
Create a `.env` file based on `env.ts` schema:

```env
DATABASE_URL=
PGHOST=
PGDATABASE=
PGUSER=
PGPASSWORD=
ARCJET_KEY=
ARCJET_ENV=
```

4. **Run migrations**

```bash
bun run migrate.ts up
```

5. **Start the server**

```bash
bun run index.ts
```

## ๐Ÿง™ Migrations

This project includes a custom migration system:

- `bun run migrate.ts up` โ€“ Apply new migrations
- `bun run migrate.ts down` โ€“ Rollback applied migrations
- Uses **PostgreSQL advisory locks** to prevent race conditions
- Tracks executed migrations in a custom table

Migration files live in:

```bash
server/db/migrations/
```

## โœ… Example Request

```bash
curl http://localhost:8080/api/products
```