pg-aura v0.2.13
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"]
);
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago