Does SQLite Work With TypeORM?

Fully CompatibleLast verified: 2026-02-26

TypeORM fully supports SQLite and is one of the best ORM choices for SQLite projects in TypeScript.

Quick Facts

Compatibility
full
Setup Difficulty
Easy
Official Integration
Yes ✓
Confidence
high
Minimum Versions
TypeORM: 0.2.0

How SQLite Works With TypeORM

TypeORM has first-class support for SQLite through the `better-sqlite3` or `sqlite3` npm packages. The integration is straightforward: you configure a DataSource with SQLite as the dialect, point it to a file path or `:memory:`, and TypeORM handles all SQL generation and migrations. The developer experience is excellent because you write standard TypeORM decorators and queries that work identically across databases. SQLite's serverless nature means zero infrastructure overhead—perfect for development, testing, Electron apps, and small-to-medium production deployments. TypeORM automatically handles SQLite's quirks like limited ALTER TABLE support by recreating tables during migrations when necessary. The combination scales well for single-file deployments and embedded scenarios, though you should be aware of SQLite's write-locking behavior in high-concurrency contexts.

Best Use Cases

Desktop applications built with Electron where you need a bundled relational database
Development and testing environments where spinning up PostgreSQL/MySQL is overkill
Mobile backends (React Native, NestJS APIs) with SQLite as the local storage layer
Small SaaS products or internal tools with moderate traffic that prioritize simplicity over horizontal scaling

Quick Setup

bash
npm install typeorm better-sqlite3 reflect-metadata
typescript
import 'reflect-metadata';
import { DataSource } from 'typeorm';
import { User } from './entity/User';

const AppDataSource = new DataSource({
  type: 'better-sqlite3',
  database: './database.sqlite',
  synchronize: true,
  logging: false,
  entities: [User],
  migrations: [],
  foreignKeys: true,
});

AppDataSource.initialize()
  .then(() => {
    console.log('Database connected');
    const userRepo = AppDataSource.getRepository(User);
    return userRepo.find();
  })
  .then(users => console.log(users))
  .catch(error => console.log(error));

Known Issues & Gotchas

warning

SQLite doesn't support concurrent writes well; multiple processes writing simultaneously will hit SQLITE_BUSY errors

Fix: Use connection pooling, implement retry logic with exponential backoff, or scale vertically instead of horizontally

warning

TypeORM migrations that use ALTER TABLE extensively may be slow or fail on SQLite due to its limited ALTER support

Fix: TypeORM auto-recreates tables for unsupported alterations, but test migrations in development first

info

Foreign key constraints are disabled by default in SQLite; you must explicitly enable them

Fix: Set `foreignKeys: true` in your DataSource options or run `PRAGMA foreign_keys = ON`

info

Large datasets (100M+ rows) will see degraded performance compared to dedicated database engines

Fix: Consider migrating to PostgreSQL/MySQL if you outgrow SQLite's performance characteristics

Alternatives

  • Prisma + SQLite: Modern ORM with excellent DX, but less flexible for complex queries
  • Sequelize + SQLite: Mature Node.js ORM with good SQLite support, but less TypeScript-native than TypeORM
  • Drizzle ORM + SQLite: Lightweight SQL-like query builder with strong type safety, better for raw SQL control

Resources

Related Compatibility Guides

Explore more compatibility guides