0.1.13 • Published 4 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
4 years ago
0.1.10
4 years ago
0.1.11
4 years ago
0.1.12
4 years ago
0.1.8
4 years ago
0.1.9
4 years ago
0.1.7
4 years ago
0.1.6
4 years ago
0.1.4
4 years ago
0.1.5
4 years ago
0.1.0
4 years ago
0.1.2
4 years ago
0.1.1
4 years ago
0.1.3
4 years ago
0.0.14
4 years ago
0.0.13
4 years ago
0.0.12
4 years ago
0.0.10
4 years ago
0.0.11
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago
1.0.0
4 years ago