1.3.2 • Published 10 months ago

pg-fixtures-editor v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

pg-fixtures-editor

Library with some utilities to edit SQL fixtures for Postgres databases.

It uses pgsql-ast-parser to parse and emit SQL code.

Rationale

Have you ever had to edit a SQL fixture after a DB schema migration? If you have, you know it's a real pain. This library aims to make this process easier.

Features

The API of this library exposes these functions:

  • removeColumn: removes a column from INSERT statements.
  • addColumn: adds a column and its value to INSERT statements. Note that the value will be emitted "as is", so you need to include proper quoting and escaping if needed. Example: to insert a SQL string, you need to pass 'your string' as columnValue (i.e. enclosed with single quotes).

Installation

npm install pg-fixtures-editor

Usage

import { removeColumn } from "pg-fixtures-editor";

const sql = `
    INSERT INTO users (id, name, email) VALUES
    (1, 'John', 'john@example.com'),
    (2, 'Jane', 'jane@example.com')
`;
const newSql = removeColumn("email", sql);

Quirks

While this project aims for a very specific and limited feature set, it's in early development stage and its API might break.

Some quirks:

  • At the moment, comments are not preserved.
  • Spacing and formatting is not always preserved.
  • The output SQL aims to be human readable when possible (e.g. multi-line INSERT statements).

Hopefully those quirks shouldn't matter too much when editing SQL fixtures.

Development

Build the project:

npm run build

Run tests:

npm test

Publish a new version:

npm run pub
1.3.2

10 months ago

1.3.1

10 months ago

1.3.0

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago