Handling TypeORM migrations in Electron apps

This page summarizes the projects mentioned and recommended in the original post on dev.to

SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  1. better-sqlite3

    The fastest and simplest library for SQLite3 in Node.js.

    To set up the required libraries, install TypeORM, better-sqlite3, and their TypeScript types:

  2. SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
  3. TypeORM

    ORM for TypeScript and JavaScript. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

    // src/main/database/dataSource.ts import path from "node:path"; import "reflect-metadata"; import { DataSource } from "typeorm"; import { UserEntity } from "./entities/user/user.entity"; import { PostEntity } from "./entities/post/post.entity"; const isElectron = !!process.versions.electron; # simple trick to see if the data source is called from the Electron app or CLI (for migrations scripts) const isProduction = process.env.NODE_ENV === "production"; let databasePath: string; if (isElectron) { // eslint-disable-next-line @typescript-eslint/no-require-imports const { app } = require("electron"); databasePath = path.join( app.getPath("userData"), app.isPackaged ? "app-name.sqlite" : "app-name.dev.sqlite" ); } else { // use hardcoded path for running migrations in development (macOS) databasePath = path.join( "/Users/user/Library/Application Support/app-name/", isProduction ? "app-name.sqlite" : "app-name.dev.sqlite" ); } // https://typeorm.io/data-source-options#better-sqlite3-data-source-options const dataSource = new DataSource({ type: "better-sqlite3", database: databasePath, entities: [UserEntity, PostEntity], migrations: [ path.join(__dirname, isElectron ? "database" : "", "/migrations/*.{js,ts}"), ], synchronize: false, # important logging: true # use this for debugging }); export const entityManager = dataSource.createEntityManager(); export default dataSource;

  4. pnpm

    Fast, disk space efficient package manager

    I started with a basic Electron + TypeScript + React project and use pnpm as my package manager. This tutorial assumes you already have a working Electron app.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • SQLSync – Stop Building Databases

    7 projects | news.ycombinator.com | 1 Dec 2023
  • Running PostgreSQL, MongoDB, and NestJS concurrently with Docker Compose

    7 projects | dev.to | 6 Jan 2025
  • Sqlite3 WebAssembly

    20 projects | news.ycombinator.com | 15 Oct 2024
  • The main steps I follow when kicking off Node.js projects

    12 projects | dev.to | 7 Oct 2024
  • Rust GraphQL APIs for NodeJS Developers: Introduction

    7 projects | dev.to | 8 Feb 2024