Registry / database / typeorm-with-better-sqlite3

typeorm-with-better-sqlite3

JSON →
library0.2.27jsnpmunverified

TypeORM is an ORM for TypeScript and JavaScript (ES5+) that supports both Active Record and Data Mapper patterns. It runs in Node.js, browsers, Cordova, Ionic, React Native, and Electron, and works with MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, sql.js, and MongoDB. Current stable version is 0.2.x (actively maintained, with frequent releases and a migration to 0.3.x in progress). Key differentiators: supports multiple databases simultaneously, CLIs for migrations and entities, and a rich decorator-based entity definition. Heavily influenced by Hibernate and Doctrine.

npm install typeorm-with-better-sqlite3
INSTALL
IMPORT
SIG · TYPEORM-WITH-BETTE
T
typeorm-with-better-sqlite3
databasejavascriptv0.2.27
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createConnection
✓ import { createConnection } from 'typeorm'
✗ import { createConnection } from 'typeorm' // correct, no wrong pattern
Default import of createConnection is commonly used, but in v0.3.x it's deprecated in favor of createConnections or DataSource.
Entity
✓ import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
✗ import { Entity } from 'typeorm' // correct; ensure reflect-metadata is imported in tsconfig
Decorators like @Entity are used for entity definitions. In TypeScript, enable 'experimentalDecorators' and 'emitDecoratorMetadata' in tsconfig.
getRepository
✓ import { getRepository } from 'typeorm'
✗ import { getRepository } from 'typeorm' // correct; also available via connection.getRepository()
In v0.3.x, getRepository is deprecated in favor of using DataSource.getRepository().
DataSource
✓ import { DataSource } from 'typeorm'
✗ import { DataSource } from 'typeorm' // correct, but only in v0.3.x and above
DataSource is the new way to manage connections starting from v0.3.0. In v0.2.x, use createConnection.
Migration
✓ import { MigrationInterface, QueryRunner } from 'typeorm'
✗ import { Migration } from 'typeorm' // wrong: Migration is not a named export, use MigrationInterface
Migrations implement MigrationInterface, not just Migration.

This example creates a SQLite database, defines a User entity, saves a record, and retrieves all users using TypeORM's Data Mapper pattern.

import 'reflect-metadata'; import { createConnection, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'; @Entity() class User { @PrimaryGeneratedColumn() id: number; @Column() firstName: string; @Column() lastName: string; } async function main() { const connection = await createConnection({ type: 'sqlite' as const, database: 'database.sqlite', entities: [User], synchronize: true, logging: false, }); const user = new User(); user.firstName = 'Timber'; user.lastName = 'Saw'; await connection.manager.save(user); console.log('Saved a new user with id: ' + user.id); const users = await connection.manager.find(User); console.log('Loaded users: ', users); } main().catch(error => console.log(error));
Debug
Known issues
breakingVersion 0.3.0 replaced createConnection with DataSource; connection options may differ.
fix
Use new DataSource({...}) and call .initialize() instead of createConnection.
affects: >=0.3.0
deprecatedgetRepository and getManager are deprecated in v0.3.0; use DataSource.getRepository() and DataSource.manager.
fix
Access repositories via DataSource instance: dataSource.getRepository(Entity).
affects: >=0.3.0
gotchareflect-metadata must be imported at the top of your application entry point; missing import causes decorators not to work.
fix
Add 'import 'reflect-metadata';' at the very top of your main file.
affects: *
gotchaTypeScript decorator support requires 'experimentalDecorators' and 'emitDecoratorMetadata' set to true in tsconfig.json.
fix
Set "experimentalDecorators": true and "emitDecoratorMetadata": true in compilerOptions.
affects: *
deprecatedThe findOne() method in v0.3.x returns null if not found; in v0.2.x it returned undefined.
fix
Check for null instead of undefined when no entity is found.
affects: >=0.3.0
breakingIn v0.3.x, the 'logging' option has changed; boolean true/false is deprecated, use an array like ['query', 'error'].
fix
Set logging: ['query', 'error'] or use a logging object.
affects: >=0.3.0
gotchaWhen using SQLite, the 'type' must be exactly 'sqlite' (lowercase) and 'database' string is the file path.
fix
Use 'sqlite' as the type (not 'sqlite3' or 'SQLite').
affects: *
Errors
Common errors & fixes
No repository for "User" was found. Looks like this entity is not registered in your current connection?
Entity not added to the connection options 'entities' array.
fix
Add the entity to the entities array in the connection or DataSource config: entities: [User] or entities: ['dist/**/*.entity.js'].
Cannot use import statement outside a module
Using ES6 import in a CommonJS context without transpilation.
fix
Configure TypeScript to emit CommonJS modules (module: 'commonjs' in tsconfig.json) or use a bundler.
Cannot find module 'typeorm'
Package not installed or incorrect import path.
fix
Run 'npm install typeorm' and verify the import path is correct (e.g., 'typeorm').
MissingDriverError: Wrong driver: "sqlite" given.
Missing SQLite driver package; sql.js or better-sqlite3 not installed.
fix
Install the appropriate driver: 'npm install sql.js' or 'npm install better-sqlite3'.
Upgrade
Version history
0.2.27latest on npm
Audit
Dependencies
reflect-metadataoptionalRequired for decorator metadata emission in TypeScript
Agent activity
13 hits · last 30 days
node
10
Amazon
1
Bingbot
1
OpenAI (training)
1
Resources
typeorm-with-better-sqlite3 — npm install typeorm-with-better-sqlite3 · libregistry