ORM for flexible queries to postgresql databases. It will only query the fields that you ask for.
npm install --save nachmorm
const entities = [
{
name: 'Book',
fields: [
{ name: 'id', type: 'string' },
{ name: 'title', type: 'string' },
{ name: 'pageCount', type: 'number' },
],
manyToOne: [{ name: 'writer', targetEntity: 'Writer', targetField: 'id' }],
},
{.md
name: 'Writer',
fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
],
oneToMany: [
{ name: 'books', targetEntity: 'Book', targetManyToOne: 'writer' },
],
},
];
const nachmorm = new Nachmorm(
{
connection: {
host: 'localhost',
user: 'youruser',
password: 'yourpassword',
database: 'yourdatabasename',
},
},
entities
);
const connection = await nachmorm.connect();
const result = await connection.select('Book', {
name: 'books',
fields: ['id', title],
});
const result = await connection.select('Book', {
name: 'books',
fields: ['id', 'title'],
args: {
where: {
id: { _eq: 'yourid' },
},
orderBy: { writer: { name: 'ASC' } },
limit: 12,
offset: 10,
},
});
const result = await connection.select('Book', {
name: 'books',
fields: [
'id',
{
name: 'writer',
fields: [
'name',
{
name: 'books',
fields: ['title'],
},
],
},
],
});