sqldiff

0.3.0 • Public • Published

sqldiff Build Status

Diff SQL table definitions to produce statements to patch them. This module does not execute any SQL.

Installation

npm install sqldiff

Example

import { Table, SchemaDiffer, Postgres, SQLite } from 'sqldiff';

// boilerplate to build up old/new table definitions
const oldTable = new Table('users');
const newTable = new Table('users');

oldTable.addColumn('id', 'pk');
oldTable.addColumn('name', 'string');

newTable.addColumn('id', 'pk');
newTable.addColumn('name', 'string');
newTable.addColumn('description', 'string');
newTable.addColumn('age', 'integer');
newTable.addColumn('height', 'double');

// generate a diff of the tables
const differ = new SchemaDiffer({ tables: [oldTable] },
                                { tables: [newTable] });

// now we can turn it into different SQL dialects
const pg = new Postgres(differ);
console.log(pg.generate());

// ALTER TABLE "users" ADD COLUMN "description" text;
// ALTER TABLE "users" ADD COLUMN "age" bigint;
// ALTER TABLE "users" ADD COLUMN "height" float;


const sqlite = new SQLite(differ);
console.log(sqlite.generate());

// ALTER TABLE `users` ADD COLUMN `description` TEXT;
// ALTER TABLE `users` ADD COLUMN `age` INTEGER;
// ALTER TABLE `users` ADD COLUMN `height` REAL;

Readme

Keywords

none

Package Sidebar

Install

npm i sqldiff

Weekly Downloads

20

Version

0.3.0

License

BSD

Unpacked Size

179 kB

Total Files

57

Last publish

Collaborators

  • zhm
  • fulcrumapp