0.2.13 • Published 3 years ago

pg-aura v0.2.13

Weekly downloads
112
License
-
Repository
github
Last release
3 years ago

pg-aura

Simplified PostgreSQL client built using node-postgres

The main purpose of this library is to provide ease of use and to protect your database from SQL injections.

  npm install pg-aura

Usage

(async function() {
  var aura = await require('pg-aura').connect({
    db_host: "127.0.0.1",
    db_super_usr: "postgres",
    db_super_pwd: "POSTGRES_PASSWORD",
    db_name: "DATABASE_NAME"
  });

  var table = await aura.table('table_name', {
    columns: {
      name: 'varchar(256)',
      last_name: 'varchar(256)',
      float: 'float(8)',
      big_int: 'BIGINT',
      text_array: 'text[]'
    }
  });

  // ...

})()

Foreign keys

when you want to use foreign keys do:

    let album_table = await cms.aura.table("albums", {
      columns: {
        id: 'SERIAL PRIMARY KEY',
        title: 'text',
        description: 'text'
      }
    });


    let media_table = await cms.aura.table('media', {
      columns: {
        id: 'serial',
        title: 'text',
        text: 'text',
        name: 'text',
        src: 'text',
        album: 'integer REFERENCES albums(id)'
      }
    });

Table API

table.insert( {obj} );

Insert by passing an argument object with at least one value named same as one column from the table.

  const id = await table.insert({
    name: "Aura",
    big_int: 987654321,
    text_array: ["One", "Two", "Three"]
  });

table.select("columns"[], "where", valuesmixed)

Select rows from a table.

columns:

"string" || array"string" i.e. "*" || "column_name"

where:

"string" i.e. "column_a = $1 OR column_b = $2"

values:

arraymixed i.e. "One", 2 these values will represent parameters ($1, $2) used in where condition

  var auras = await table.select(
    ['name', 'float', 'big_int', 'text_array'],
    "name = $1",
    ["Aura"]
  );

  // OR

  var auras = await table.select(
    '*', "name = $1", ["Aura"]
  );

  // OR

  var auras = await table.select('*');

table.update(set{obj}, "where", valuesmixed)

Update rows within a table.

set:

{obj} i.e. { column_name: "new value" }

where:

"string" i.e. "column_a = $1 OR column_b = $2"

values:

arraymixed i.e. "One", 2 these values will represent parameters ($1, $2) used in where condition

  await table.update(
    { name: "NEW NAME", float: 4.842 },
    "name = $1",
    ["Aura"]
  );

table.delete("where", valuesmixed)

Delete rows within a table.

where:

"string" i.e. "column_a = $1 OR column_b = $2"

values:

arraymixed i.e. "One", 2 these values will represent parameters ($1, $2) used in where condition

values: arraymixed i.e. "One", 2 these values will represent parameters ($1, $2) used in where condition

  await table.delete(
    "name = $1",
    ["Aura"]
  );
0.2.13

3 years ago

0.2.12

4 years ago

0.2.10

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago