nachmorm
TypeScript icon, indicating that this package has built-in type declarations

0.1.13 • Public • Published

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'],
        },
      ],
    },
  ],
});

Readme

Keywords

none

Package Sidebar

Install

npm i nachmorm

Weekly Downloads

0

Version

0.1.13

License

ISC

Unpacked Size

121 kB

Total Files

53

Last publish

Collaborators

  • nachmo5