0.1.13 • Published 5 years ago
nachmorm v0.1.13
Nachmorm
ORM for flexible queries to postgresql databases. It will only query the fields that you ask for.
Install
npm install --save nachmorm
Define your entities
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' },
],
},
];
Create orm instance
const nachmorm = new Nachmorm(
{
connection: {
host: 'localhost',
user: 'youruser',
password: 'yourpassword',
database: 'yourdatabasename',
},
},
entities
);
Get connection
const connection = await nachmorm.connect();
Simple query
const result = await connection.select('Book', {
name: 'books',
fields: ['id', title],
});
Query With arguments
const result = await connection.select('Book', {
name: 'books',
fields: ['id', 'title'],
args: {
where: {
id: { _eq: 'yourid' },
},
orderBy: { writer: { name: 'ASC' } },
limit: 12,
offset: 10,
},
});
Multi level query
const result = await connection.select('Book', {
name: 'books',
fields: [
'id',
{
name: 'writer',
fields: [
'name',
{
name: 'books',
fields: ['title'],
},
],
},
],
});
0.1.13
5 years ago
0.1.10
5 years ago
0.1.11
5 years ago
0.1.12
5 years ago
0.1.8
5 years ago
0.1.9
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.4
5 years ago
0.1.5
5 years ago
0.1.0
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.3
5 years ago
0.0.14
5 years ago
0.0.13
5 years ago
0.0.12
5 years ago
0.0.10
5 years ago
0.0.11
5 years ago
0.0.9
5 years ago
0.0.8
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.5
5 years ago
0.0.4
5 years ago
0.0.3
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago
1.0.0
5 years ago