A Sakila database data synchronization and CLI tool built with TypeORM, supporting dual databases (MySQL/SQLite3) and providing full data synchronization, automatic entity generation, and unit testing capabilities.
Core Features: Full data synchronization for Sakila database
dimension tables (e.g., film, actor, category)
Tech Stack: TypeScript + TypeORM + MySQL/SQLite3 + Commander (CLI) +
Jest (Testing)
Highlights: entity generation, command-line sync
execution, and comprehensive test coverage
-
Node.js ≥ 14.17.0 (v16+ recommended)
-
npm ≥ 5.2.0
-
Databases: MySQL and SQLite3
-
Optional Global Dependencies:
npm install -g ts-node typeorm-model-generator
# Initialize TypeORM project (MySQL template)
typeorm init --name SakilaTyperomMySQL --database mysql
cd SakilaTyperomMySQL
# Install core dependencies
npm install sqlite3 --save
npm install commander date-fns --save
# Install dev dependencies
npm install --save-dev ts-node typescript jest ts-jest @types/jestimport { DataSource } from "typeorm";
export const AppDataSource = new DataSource({
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "your password",
database: "sakila",
entities: [__dirname + "/entity/**/*.ts"],
synchronize: false,
logging: false,
});import { DataSource } from "typeorm";
export const AppDataSource = new DataSource({
type: "sqlite",
database: "sakila.sqlite",
entities: [__dirname + "/entity/**/*.ts"],
synchronize: false,
logging: false,
});npx typeorm-model-generator -h localhost -d sakila -u root -x 'your password' -e mysql -o src/entityGenerated entity files automatically map to database table structures.
npx ts-node src/sync/full-load-dim-film.ts
npx ts-node src/sync/full-load-dim-actor.ts
npx ts-node src/sync/full-load-dim-category.tsAdd to package.json:
{
"scripts": {
"full-load": "ts-node src/cli.ts full-load",
"test": "jest"
}
}Run:
npm run full-loadnpm run test