# pckg-orm

> A simple JS ORM

Latest version **0.0.5** (published 2021-07-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install pckg-orm
pnpm add pckg-orm
yarn add pckg-orm
bun add pckg-orm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-07-25 |
| First published | 2021-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12.0.0 |
| Dependencies | 0 |
| Unpacked size | 29 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bojan Rajh |
| Maintainers | schtr4jh |
| Keywords | package, frontend |

## Links

- npm: https://www.npmjs.com/package/pckg-orm
- Repository: https://github.com/pckg/orm
- Issues: https://github.com/pckg/orm/issues
- npm.io page: https://npm.io/package/pckg-orm

## Recent versions

- 0.0.5 (latest) — 2021-07-25
- 0.0.4 — 2021-07-17
- 0.0.3 — 2021-04-24
- 0.0.2 — 2021-03-15
- 0.0.1-e — 2021-03-15
- 0.0.1-d — 2021-03-11
- 0.0.1-c — 2021-03-10
- 0.0.1-b — 2021-03-09
- 0.0.1-a — 2021-02-10

## README

# pckg/orm

A simple JS ORM that just works with [pckg](https://github.com/pckg).

# Usage

Require `pckg-orm` package with `npm` or `yarn`.

` $ yarn add pckg-orm`

## Entities

Entities represent full or partial collection of records.

```
import {Entity} from "pckg-orm/src/orm";

export class Countries extends Entity {
    constructor(repository) {
        super(repository);
        this.$record = Country;
        this.$path = 'countries';
    }
}
```

# Fetching

You can fetch and filter items.

```
await = new Countries()
        .where('continent', 'EU')
        .orderBy('title', 'ASC')
        .limit(10, 20)
        .all();
```

## Records

Records represent a single item from collection.

```
import {Record} from "pckg-orm/src/orm;

export class Country extends Record {
    constructor(props) {
        super(props);
        this.$entity = Countries;
    }
}
```

# Save, update, delete and clone.

You can manage your items with default actions that all return a `Promise`.

```
let country = new Country({
    title: 'Slovenia',
    iso2: 'si',
    iso3: 'svn',
    phone: '00386',
});
await country.save(); // or insert()
country.continent = 'EU';
await country.save(); // or update()
await country.delete();
```

## Repositories

Repositories represent a remote or local data source where entities are fetched from and records are saved to. They
define a querying layer.

## Rest

Get records - `GET /api/countries?continent=EU`

Insert record -`POST - /api/countries`

Update record - `POST - /api/countries/id`

`PUT /api/countries/id`

`PATCH /api/countries/id`

Delete record - `DELETE /api/countries/id`

## HTTPQL

`GET /api/httpql` + X-Pckg-Orm- headers

`POST /api/httpql` + `countries:update`, `countries:delete`, `countries:insert` actions

---
_Source: https://npm.io/package/pckg-orm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
