0.0.19 • Published 11 months ago
pg-lightquery v0.0.19
pgquery
With this module you'll be able to synthetize your postgreSQL database in just one file. Then, using an object-oriented approach, it will be possible to manipulate the database without hussle.
pgConfig
Use a file to config Postgres access and database schema, like:
const modelsConfig = {
users: {
tableName: 'users',
schema: {
id: {
type: 'SERIAL',
primaryKey: true,
},
name: {
type: 'TEXT',
notNull: true,
},
email: {
type: 'TEXT',
notNull: true,
unique: true,
},
createdAt: {
type: 'TIMESTAMP',
notNull: true,
default: 'NOW()',
},
updatedAt: {
type: 'TIMESTAMP',
notNull: true,
default: 'NOW()',
},
},
queries: {
createUser: {
sql: 'INSERT INTO users(name, email) VALUES($1, $2) RETURNING *',
type:'insert',
values: ({ name, email }: UserData) => [name, email],
processResult: (result: QueryResult<UserResult>) => result.rows[0],
},
getUserById: {
sql: 'SELECT * FROM users',
type:'select',
values: (id: number) => [id],
processResult: (result: QueryResult<UserResult>) => result.rows[0],
},
},
},
}
Special Queries
Use params like field.condition like {createdAt.startDate: '2023-01-01'}
as params
0.0.10
11 months ago
0.0.11
11 months ago
0.0.12
11 months ago
0.0.13
11 months ago
0.0.14
11 months ago
0.0.15
11 months ago
0.0.16
11 months ago
0.0.17
11 months ago
0.0.18
11 months ago
0.0.19
11 months ago
0.0.9
1 year ago
0.0.8
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago