Skip to content

Installation ​

Packages ​

Aim's database packages can be used independently:

PackageUse Case
aim_databaseAbstraction layer only (for custom driver implementations)
aim_postgresPostgreSQL connection (includes aim_database)
aim_sqliteSQLite connection (includes aim_database) — not yet published to pub.dev, see SQLite below
aim_ormORM abstraction layer
aim_orm_postgresPostgreSQL ORM (includes aim_orm + aim_postgres)

PostgreSQL ​

In most cases, add the PostgreSQL driver directly:

bash
dart pub add aim_postgres

This also adds aim_database as a dependency.

pubspec.yaml ​

yaml
dependencies:
  aim_postgres: ^0.4.0

Verify Installation ​

dart
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
ParameterDescriptionDefault
userUsernamerequired
passwordPasswordrequired
hostServer hostnamelocalhost
portServer port5432
databaseDatabase namerequired
sslmodeSSL modeprefer

SSL Modes ​

ModeDescription
disableNo SSL
allowTry non-SSL first, then SSL
preferTry SSL first, then non-SSL
requireSSL required
verify-caSSL + verify CA
verify-fullSSL + 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 ​

dart
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 ​

Released under the MIT License.