Database Setup Guide
Complete guide to setting up and configuring databases for your Flowfull backend.
Supported Databases
Flowfull supports multiple database types through Kysely ORM:
| Database | Type | Best For |
|---|---|---|
| PostgreSQL | Traditional | Production, complex queries, full-text search |
| MySQL | Traditional | Production, compatibility, wide hosting support |
| LibSQL/Turso | Serverless | Edge deployments, low latency, global distribution |
| Neon | Serverless | Serverless Postgres, auto-scaling |
| PlanetScale | Serverless | Serverless MySQL, branching workflows |
PostgreSQL Setup
Local Development
bash
docker run --name flowfull-postgres \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=flowfull \
-p 5432:5432 \
-d postgres:16bash
brew install postgresql@16
brew services start postgresql@16
createdb flowfullbash
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo -u postgres createdb flowfullConfiguration
env
DATABASE_TYPE=postgresql
DATABASE_URL=postgresql://postgres:password@localhost:5432/flowfullInstall Driver
bash
npm install pgbash
yarn add pgbash
bun add pgMySQL Setup
Local Development
bash
docker run --name flowfull-mysql \
-e MYSQL_ROOT_PASSWORD=password \
-e MYSQL_DATABASE=flowfull \
-p 3306:3306 \
-d mysql:8bash
brew install mysql
brew services start mysql
mysql -u root -e "CREATE DATABASE flowfull;"bash
sudo apt update
sudo apt install mysql-server
sudo systemctl start mysql
sudo mysql -e "CREATE DATABASE flowfull;"Configuration
env
DATABASE_TYPE=mysql
DATABASE_URL=mysql://root:password@localhost:3306/flowfullInstall Driver
bash
npm install mysql2bash
yarn add mysql2bash
bun add mysql2LibSQL/Turso Setup
Create Database
- Sign up at turso.tech
- Install Turso CLI:
bash
curl -sSfL https://get.tur.so/install.sh | bash- Create database:
bash
turso db create flowfull- Get connection URL:
bash
turso db show flowfull --url- Get auth token:
bash
turso db tokens create flowfullConfiguration
env
DATABASE_TYPE=libsql
DATABASE_URL=libsql://flowfull-your-org.turso.io
DATABASE_AUTH_TOKEN=your-auth-token-hereInstall Driver
bash
npm install @libsql/clientbash
yarn add @libsql/clientbash
bun add @libsql/clientNeon Setup
Create Database
- Sign up at neon.tech
- Create a new project
- Copy connection string
Configuration
env
DATABASE_TYPE=postgresql
DATABASE_URL=postgresql://user:password@ep-xxx.neon.tech/flowfull?sslmode=requireInstall Driver
Same as PostgreSQL:
bash
bun add pgPlanetScale Setup
Create Database
- Sign up at planetscale.com
- Create a new database
- Create a branch (e.g.,
main) - Get connection string
Configuration
env
DATABASE_TYPE=mysql
DATABASE_URL=mysql://user:password@aws.connect.psdb.cloud/flowfull?ssl={"rejectUnauthorized":true}Install Driver
Same as MySQL:
bash
bun add mysql2Database Initialization
Create Database Instance
typescript
// src/lib/database.ts
import { Kysely } from 'kysely';
import { PostgresDialect } from 'kysely';
import { Pool } from 'pg';
const dialect = new PostgresDialect({
pool: new Pool({
connectionString: process.env.DATABASE_URL,
max: 10,
})
});
export const db = new Kysely<Database>({
dialect,
});Define Schema Types
typescript
// src/lib/database.types.ts
export interface Database {
users: UsersTable;
sessions: SessionsTable;
// ... more tables
}
export interface UsersTable {
id: string;
email: string;
name: string;
created_at: Date;
updated_at: Date;
}
export interface SessionsTable {
id: string;
user_id: string;
expires_at: Date;
created_at: Date;
}Query Examples
Basic Queries
typescript
// Select with conditions
const users = await db
.selectFrom('users')
.select(['id', 'email', 'name'])
.where('is_verified', '=', true)
.execute();
// Insert
const newUser = await db
.insertInto('users')
.values({
id: generateId(),
email: 'user@example.com',
name: 'John Doe',
})
.returningAll()
.executeTakeFirst();
// Update
await db
.updateTable('users')
.set({ name: 'Jane Doe' })
.where('id', '=', userId)
.execute();
// Delete
await db
.deleteFrom('users')
.where('id', '=', userId)
.execute();Advanced Queries
typescript
// Join tables
const postsWithAuthors = await db
.selectFrom('posts')
.innerJoin('users', 'users.id', 'posts.user_id')
.select([
'posts.id',
'posts.title',
'users.name as author_name',
])
.execute();
// Pagination
const page = 1;
const limit = 20;
const offset = (page - 1) * limit;
const posts = await db
.selectFrom('posts')
.selectAll()
.orderBy('created_at', 'desc')
.limit(limit)
.offset(offset)
.execute();Best Practices
1. Use PostgreSQL or LibSQL/Turso for Production
- PostgreSQL: Best for traditional deployments with complex queries and high traffic
- LibSQL/Turso: Best for edge deployments, global distribution, and serverless architectures
- MySQL: Good alternative for compatibility and wide hosting support
2. Enable Connection Pooling
Configure appropriate pool sizes based on your traffic:
env
DATABASE_POOL_MIN=2
DATABASE_POOL_MAX=103. Use SSL in Production
Always enable SSL for production databases:
env
# PostgreSQL with SSL
DATABASE_URL=postgresql://user:password@host:5432/db?sslmode=require
# MySQL with SSL
DATABASE_URL=mysql://user:password@host:3306/db?ssl={"rejectUnauthorized":true}4. Monitor Performance
- Track query performance
- Monitor connection pool usage
- Set up alerts for slow queries
- Use database-specific monitoring tools
5. Regular Backups
Set up automated backups for your production database. Most cloud providers offer automated backup solutions.
Next Steps
- Multi-Database Support - Learn about database abstraction
- Environment Config - Configure database connection
- Deployment - Deploy with database
Need Help?
- 🌐 Notside.com - Professional database architecture
- 📧 Email: contact@notside.com