1.0.12 • Published 1 year ago

@uql/core v1.0.12

Weekly downloads
7
License
MIT
Repository
github
Last release
1 year ago

uql · license tests coverage status npm version

Quick Start

uql is a flexible and efficient ORM, with declarative JSON syntax and really smart type-safety.

The uql queries can be safely written in the frontend (browser/mobile) and sent to the backend; or only use uql in the backend, or even in a mobile app with an embedded database (like sqlite).

Features

Installation

  1. Install the core package:
npm install @uql/core --save

or

yarn add @uql/core
  1. Install one of the specific packages according to your database:
DatabasePackage
MySQL@uql/mysql
PostgreSQL@uql/postgres
MariaDB@uql/maria
MongoDB@uql/mongo
SQLite@uql/sqlite

E.g. for PostgreSQL

npm install @uql/postgres --save

or with yarn

yarn add @uql/postgres
  1. Additionally, your tsconfig.json may need the following flags:
"target": "es2020",
"experimentalDecorators": true,
"emitDecoratorMetadata": true

Configuration

A default querier-pool can be set in any of the bootstrap files of your app (e.g. in the server.ts).

import { setQuerierPool } from '@uql/core';
import { PgQuerierPool } from '@uql/postgres';

const querierPool = new PgQuerierPool(
  {
    host: 'localhost',
    user: 'theUser',
    password: 'thePassword',
    database: 'theDatabase',
  },
  // a logger can optionally be passed so the SQL queries are logged
  console.log
);

setQuerierPool(querierPool);

Definition of Entities

Take any dump class (aka DTO) and annotate it with the decorators from '@uql/core/entity'.

import { v4 as uuidv4 } from 'uuid';
import { Field, ManyToOne, Id, OneToMany, Entity, OneToOne, ManyToMany } from '@uql/core/entity';

@Entity()
export class Profile {
  /**
   * primary-key.
   * the `onInsert` callback can be used to specify a custom mechanism for auto-generating
   * the default value of a field when inserting a new record.
   */
  @Id({ onInsert: uuidv4 })
  id?: string;
  @Field()
  picture?: string;
  /**
   * foreign-keys are really simple to specify.
   */
  @Field({ reference: () => User })
  creatorId?: string;
}

@Entity()
export class User {
  @Id({ onInsert: uuidv4 })
  id?: string;
  @Field()
  name?: string;
  @Field()
  email?: string;
  @Field()
  password?: string;
  /**
   * `mappedBy` can be a callback or a string (callback is useful for auto-refactoring).
   */
  @OneToOne({ entity: () => Profile, mappedBy: (profile) => profile.creatorId, cascade: true })
  profile?: Profile;
}

@Entity()
export class MeasureUnitCategory {
  @Id({ onInsert: uuidv4 })
  id?: string;
  @Field()
  name?: string;
  @OneToMany({ entity: () => MeasureUnit, mappedBy: (measureUnit) => measureUnit.category })
  measureUnits?: MeasureUnit[];
}

@Entity()
export class MeasureUnit {
  @Id({ onInsert: uuidv4 })
  id?: string;
  @Field()
  name?: string;
  @Field({ reference: () => MeasureUnitCategory })
  categoryId?: string;
  @ManyToOne({ cascade: 'persist' })
  category?: MeasureUnitCategory;
}

Query the data

import { getQuerier } from '@uql/core';
import { User } from './entity';

const querier = await getQuerier();

const id = await this.querier.insertOne(User, {
  email: 'lorem@example.com',
  profile: { picture: 'ipsum.jpg' },
});

const users = await querier.findMany(User, {
  $project: { id: true, email: true, profile: ['picture'] },
  $filter: { email: { $iendsWith: '@google.com' } },
  $sort: { createdAt: -1 },
  $limit: 100,
});

await querier.release();

See more in https://nukak.org :high_brightness:

1.0.12

1 year ago

1.0.11

2 years ago

1.0.9

2 years ago

1.0.10

2 years ago

0.4.95

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

0.4.93

2 years ago

0.4.91

2 years ago

0.4.92

2 years ago

0.4.90

2 years ago

0.4.86

2 years ago

0.4.87

2 years ago

0.4.84

2 years ago

0.4.85

2 years ago

0.4.82

2 years ago

0.4.83

2 years ago

0.4.80

2 years ago

0.4.81

2 years ago

0.4.88

2 years ago

0.4.89

2 years ago

0.4.79

2 years ago

0.4.78

2 years ago

0.4.75

2 years ago

0.4.76

2 years ago

0.4.77

2 years ago

0.4.74

2 years ago

0.4.73

3 years ago

0.4.72

3 years ago

0.4.69

3 years ago

0.4.68

3 years ago

0.4.67

3 years ago

0.4.65

3 years ago

0.4.66

3 years ago

0.4.64

3 years ago

0.4.63

3 years ago

0.4.62

3 years ago

0.4.60

3 years ago

0.4.61

3 years ago

0.4.59

3 years ago

0.4.58

3 years ago

0.4.57

3 years ago

0.4.55

3 years ago

0.4.56

3 years ago

0.4.53

3 years ago

0.4.52

3 years ago

0.4.49

3 years ago

0.4.51

3 years ago

0.4.50

3 years ago

0.4.48

3 years ago

0.4.46

3 years ago

0.4.47

3 years ago

0.4.45

3 years ago

0.4.44

3 years ago

0.4.42

3 years ago

0.4.43

3 years ago

0.4.40

3 years ago

0.4.41

3 years ago

0.4.39

3 years ago

0.4.37

3 years ago

0.4.35

3 years ago

0.4.36

3 years ago

0.4.34

3 years ago

0.4.31

3 years ago

0.4.32

3 years ago

0.4.33

3 years ago

0.4.30

3 years ago

0.4.29

3 years ago

0.4.28

3 years ago

0.4.27

3 years ago

0.4.26

3 years ago

0.4.25

3 years ago

0.4.24

3 years ago

0.4.23

3 years ago

0.4.20

3 years ago

0.4.21

3 years ago

0.4.22

3 years ago

0.4.19

3 years ago

0.4.17

3 years ago

0.4.18

3 years ago

0.4.15

3 years ago

0.4.16

3 years ago

0.4.14

3 years ago

0.4.0-alpha.4

3 years ago

0.4.0-alpha.3

3 years ago

0.4.0-alpha.2

3 years ago

0.4.0-alpha.1

3 years ago

0.4.9

3 years ago

0.4.0-alpha.0

3 years ago

0.4.8

3 years ago

0.4.0-alpha.10

3 years ago

0.4.0-alpha.8

3 years ago

0.4.0-alpha.7

3 years ago

0.4.0-alpha.6

3 years ago

0.4.0-alpha.5

3 years ago

0.4.10

3 years ago

0.4.13

3 years ago

0.4.11

3 years ago

0.4.12

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.3.4

3 years ago

0.4.2

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago