1.0.16 • Published 4 years ago

postgresupdater v1.0.16

Weekly downloads
3
License
BSD-3-Clause
Repository
-
Last release
4 years ago

PostgresUpdater

installation

npm i --save postgresupdater

usage

const pg = require('postgresupdater')(host, port, user, password, database);

pg.waitForInit().then(async () => {
  console.log(pg.getVersion()); //prints out the current database version

  const data = await pg.query('SELECT * FROM "SomeTable" WHERE ID = $1', [10]); // get entry with id 10

  pg.stop(); // end database connection
});

constructor arguments:

postgresupdater(
  host,     //host to connect to
  port,     //port of the postgres server
  user,     //username
  password, //password
  database, //database to connect to
  schema,   //schema to use (default 'public')
  recreate  //if true, deletes current schema, creates an empty one and runs all update scripts on that empty schema (default: false)
)

updates

every time the module gets initialized, it searches for updates in ./updates/ in the current working directory. update files have to be named xxxx.sql with the name consisting of only numbers. all updates will be executed in ascending order. note that updates with leading 0 will not be executed since this module uses an incrementing number to find updates.

0.sql

-- first update, initializing tables
CREATE TABLE "SomeTable" (
  "ID" SERIAL,
  "Value" CHARACTER(3) NOT NULL
);

1.sql

-- insert some data
INSERT INTO "SomeTable" ("Value") VALUES ('asd');
INSERT INTO "SomeTable" ("Value") VALUES ('fgh');
INSERT INTO "SomeTable" ("Value") VALUES ('jkl');

After starting this example, the database will have one table with 3 rows of data by default

1.0.16

4 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago