This repository has been moved to GitLab
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
(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[]'
}
});
// ...
})()
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"]
});
Select rows from a table.
"string" || array["string"] i.e. "*" || ["column_name"]
"string" i.e. "column_a = $1 OR column_b = $2"
array[mixed] 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('*');
Update rows within a table.
{obj} i.e. { column_name: "new value" }
"string" i.e. "column_a = $1 OR column_b = $2"
array[mixed] 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"]
);
Delete rows within a table.
"string" i.e. "column_a = $1 OR column_b = $2"
array[mixed] i.e. ["One", 2] these values will represent parameters ($1, $2) used in where condition
values: array[mixed] i.e. ["One", 2] these values will represent parameters ($1, $2) used in where condition
await table.delete(
"name = $1",
["Aura"]
);