Skip to main content
Kit provides flexible database configuration through environment variables and a programmatic API.

Environment Variables

The simplest way to configure your database is through the .env file:

Connection String Formats

DatabaseConfig

For programmatic configuration, use DatabaseConfig:

Builder Pattern

You can also build configuration manually:

Connection Pooling

Kit automatically manages a connection pool for optimal performance. Configure pooling settings through DatabaseConfig:

Database Initialization

The database is automatically initialized when your Kit application starts. The DB::init() method is called during bootstrap:

Manual Initialization

If you need to initialize the database manually:

Accessing the Connection

Use the DB facade to access the database connection anywhere in your application:

Multiple Databases

For applications requiring multiple database connections, you can manage connections manually:

Environment-Specific Configuration

Use different configurations for development, testing, and production:

Troubleshooting

Connection Refused

If you see connection refused errors:
  1. Verify the database server is running
  2. Check the connection string format
  3. Ensure network access (firewall, security groups)

Pool Exhausted

If connections are being exhausted:
  1. Increase max_connections
  2. Ensure connections are being released (avoid long-running transactions)
  3. Check for connection leaks in your code

SQLite File Not Created

For SQLite, ensure the directory exists: