Installation
Packages
Aim's database packages can be used independently:
| Package | Use Case |
|---|---|
aim_database | Abstraction layer only (for custom driver implementations) |
aim_postgres | PostgreSQL connection (includes aim_database) |
aim_sqlite | SQLite connection (includes aim_database) — not yet published to pub.dev, see SQLite below |
aim_orm | ORM abstraction layer |
aim_orm_postgres | PostgreSQL ORM (includes aim_orm + aim_postgres) |
PostgreSQL
In most cases, add the PostgreSQL driver directly:
dart pub add aim_postgresThis also adds aim_database as a dependency.
pubspec.yaml
dependencies:
aim_postgres: ^0.4.0Verify Installation
import 'package:aim_postgres/aim_postgres.dart';
void main() async {
final db = await PostgresDatabase.connect(
'postgresql://user:pass@localhost:5432/mydb',
);
print('Connected to PostgreSQL');
final result = await db.query('SELECT version()');
print('Version: ${result.first['version']}');
await db.close();
}Connection String Format
postgresql://user:password@host:port/database?sslmode=require| Parameter | Description | Default |
|---|---|---|
user | Username | required |
password | Password | required |
host | Server hostname | localhost |
port | Server port | 5432 |
database | Database name | required |
sslmode | SSL mode | prefer |
SSL Modes
| Mode | Description |
|---|---|
disable | No SSL |
allow | Try non-SSL first, then SSL |
prefer | Try SSL first, then non-SSL |
require | SSL required |
verify-ca | SSL + verify CA |
verify-full | SSL + verify CA + hostname |
SQLite
Not yet published to pub.dev
aim_sqlite is in the dart-forge/aim repository (packages/aim_sqlite) but is not published to pub.dev yet, so there is no dart pub add aim_sqlite command or version constraint to add to pubspec.yaml today. The driver itself and the rest of this page describe what it does once it is published.
libsqlite3
Unlike aim_postgres, aim_sqlite does not talk to a server -- it loads libsqlite3 from the machine it runs on, so that library must already be installed (it ships with macOS and most Linux distributions; on Windows, place sqlite3.dll next to your executable, or point the AIM_SQLITE_LIBRARY environment variable at it). Version 3.8.7 or newer is required. See the SQLite driver page for the exact search order.
Example Usage
import 'package:aim_sqlite/aim_sqlite.dart';
void main() async {
final db = await SqliteDatabase.open('app.db');
print('Connected to SQLite');
final result = await db.query('SELECT sqlite_version() AS v');
print('Version: ${result.first['v']}');
await db.close();
}Next Steps
- PostgreSQL Driver - Detailed usage guide
- SQLite Driver - Detailed usage guide (not yet published to pub.dev)
- ORM - Type-safe query builder for PostgreSQL
