Does SQLite Work With TypeORM?
TypeORM fully supports SQLite and is one of the best ORM choices for SQLite projects in TypeScript.
Quick Facts
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
Quick Setup
npm install typeorm better-sqlite3 reflect-metadataimport '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
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
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
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`
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