Skip to Content

Database Adapters

Choose the database adapter by data model, operational profile, and the smoke test that confirms connection lifecycle.

Database adapter comparison

AdapterIntegrated technologyData modelBest fitSmoke test
InMemoryProcess-local memory storeKeyed objectsUnit tests, demos, and browser-free contract examples.bun run smoke:db:inmemory
PostgreSQLPostgreSQL through the SQL client profileRelational SQLTransactional systems with relational integrity, indexing, and reporting needs.bun run smoke:db:postgresql
MySQLMySQL through the SQL client profileRelational SQLCommon relational workloads, SaaS CRUD, and teams with MySQL operational experience.bun run smoke:db:mysql
SQL ServerMicrosoft SQL Server through the SQL client profileRelational SQLEnterprise environments standardized on Microsoft data platforms.bun run smoke:db:mssql
OracleOracle Database through the SQL client profileRelational SQLEnterprise systems already invested in Oracle operations and governance.bun run smoke:db:oracle
SQLiteEmbedded SQL database fileEmbedded relational SQLLocal development, edge prototypes, tests, and single-node utilities.bun run smoke:db:sqlite
MongoDBMongoDB through Mongoose repository wiringDocument databaseDocument-centric domains, flexible schemas, and aggregate-shaped persistence.bun run smoke:db:mongodb
DynamoDBAWS DynamoDB key-value and document databaseKey-value/documentAWS-native services that need managed scale and access-pattern-first modeling.bun run smoke:db:dynamodb
CassandraApache Cassandra wide-column databaseWide-columnVery high write volume, multi-node distribution, and query patterns known in advance.bun run smoke:db:cassandra
FirebaseFirebase emulator-backed database profileDocument/realtime app dataRapid product surfaces that benefit from Firebase tooling and local emulator validation.bun run smoke:db:firebase
AuroraAmazon Aurora-compatible relational profileManaged relational SQLAWS relational workloads needing managed operations and cloud scaling paths.bun run smoke:db:aurora
RDSAmazon RDS-compatible relational profileManaged relational SQLAWS teams standardizing managed relational databases without changing domain code.bun run smoke:db:rds

Fast guide

  • Use InMemory for tests, demos, and examples.
  • Use SQL databases when the domain needs relationships, transactions, and reporting.
  • Use SQLite for local, single-node, and file-backed environments.
  • Use MongoDB when aggregates are documents.
  • Use DynamoDB or Cassandra when access patterns and write scale are central.
  • Use Firebase when Firebase tooling and emulators help the product.

Complete selection example

type DatabaseAdapterChoice = {
  driver: string;
  smokeTest: string;
  durable: boolean;
};

const databaseChoices: DatabaseAdapterChoice[] = [
  { driver: 'InMemory', smokeTest: 'bun run smoke:db:inmemory', durable: false },
  { driver: 'PostgreSQL', smokeTest: 'bun run smoke:db:postgresql', durable: true },
  { driver: 'Mongo', smokeTest: 'bun run smoke:db:mongodb', durable: true },
  { driver: 'DynamoDB', smokeTest: 'bun run smoke:db:dynamodb', durable: true },
  { driver: 'SQLite', smokeTest: 'bun run smoke:db:sqlite', durable: true }
];

export function selectDatabaseAdapter(driver: string): DatabaseAdapterChoice {
  const choice = databaseChoices.find((item) => item.driver === driver);

  if (!choice) {
    throw new Error('Unsupported database driver: ' + driver);
  }

  return choice;
}