Automatic Configuration
When your NativePHP application starts, it automatically:- Creates a dedicated SQLite database connection named
nativephp - Sets this as the default database connection
- Configures queue and cache systems to use this database
- Optimizes SQLite settings for desktop application performance
The
nativephp connection is automatically configured and set as the default. You don’t need to manually configure it in your config/database.php file.Database Location
Production Mode
In production, the database is stored in the application’s data directory:- macOS:
~/Library/Application Support/YourApp/database.sqlite - Windows:
%APPDATA%\YourApp\database.sqlite - Linux:
~/.config/YourApp/database.sqlite
Development Mode
In development (whenAPP_DEBUG=true), the database is stored in your project’s database directory:
Database Configuration
NativePHP applies the following configuration to the SQLite database:SQLite Optimizations
NativePHP automatically applies SQLite optimizations for desktop applications:What is WAL mode?
What is WAL mode?
Write-Ahead Logging (WAL) is an alternative to the traditional rollback journal. It provides:
- Better Concurrency: Readers don’t block writers and writers don’t block readers
- Faster Performance: Most transactions are faster with WAL
- More Durable: Better protection against corruption
Queue and Cache Configuration
NativePHP automatically configures Laravel’s queue and cache systems to use thenativephp database:
Running Migrations
NativePHP provides commands for managing your database:Migrate Command
In development mode, migrations run automatically when the database is first created.
Fresh Command
Seed Command
Wipe Command
Using the Database
Use Laravel’s database features as you normally would:Multiple Database Connections
You can still use other database connections alongside the NativePHP database:config/database.php
Best Practices
- Migrations: Always use migrations to manage database schema changes
- Backups: Implement a backup strategy for user data in production
- Indexes: Add indexes to frequently queried columns for better performance
- Transactions: Use database transactions for operations that modify multiple records
Troubleshooting
Database Locked Errors
If you encounter “database is locked” errors:- Ensure WAL mode is enabled (it is by default)
- Check that the
busy_timeoutis set appropriately - Wrap long-running operations in transactions
- Consider reducing the number of concurrent queue workers
Migration Issues
If migrations aren’t running:- Verify the database file exists and is writable
- Check file permissions on the database directory
- Run migrations manually with
php artisan native:migrate - Review migration files for syntax errors
Performance Issues
To optimize database performance:- Add appropriate indexes to frequently queried columns
- Use
select()to limit the columns retrieved - Paginate large result sets
- Use eager loading to avoid N+1 query problems
- Consider using
chunk()for processing large datasets