Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/patarapolw/liteorm
A simple wrapper for sqlite; with typings based on TypeScript decorators and reflect-metadata. With async eventemitter (emittery). Focusing on JSON, Date, and MongoDB interop.
https://github.com/patarapolw/liteorm
orm sqlite typescript-decorators
Last synced: about 2 months ago
JSON representation
A simple wrapper for sqlite; with typings based on TypeScript decorators and reflect-metadata. With async eventemitter (emittery). Focusing on JSON, Date, and MongoDB interop.
- Host: GitHub
- URL: https://github.com/patarapolw/liteorm
- Owner: patarapolw
- License: mit
- Created: 2019-09-06T16:19:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-03T06:55:27.000Z (over 1 year ago)
- Last Synced: 2024-11-02T10:52:04.501Z (2 months ago)
- Topics: orm, sqlite, typescript-decorators
- Language: TypeScript
- Homepage:
- Size: 399 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# liteorm
A simple wrapper for [sqlite](https://www.npmjs.com/package/sqlite); with typings based on [TypeScript decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) and [reflect-metadata](https://www.npmjs.com/package/reflect-metadata).
[![npm version](https://badge.fury.io/js/liteorm.svg)](https://badge.fury.io/js/liteorm)
- Async eventemitter ([emittery](https://www.npmjs.com/package/emittery))
- I make sure that you can intercept query objects and raw SQL (as well as their parameters) in an async way
- ~~Auto-define `_id` as `PRIMARY KEY INTEGER AUTOINCREMENT` (Use `_id` as default name for primary key)~~
- I use ROWID, instead.
- Auto-append `createdAt`, `updatedAt` if `@Table({ timestamp: true })`
- JSON, Date, Boolean, and MongoDB interop
- Additional type `StringArray`, inspired by [Anki schema](https://github.com/ankidroid/Anki-Android/wiki/Database-Structure)
- Query with JSON, and tested with , using MongoDB-like languages, with some differences (for example, `$regex` is currently not supported, use `$like`, `$nlike`, `$substr`, `$nsubstr` instead.)
- JSON querying is supported via JSON1 extension. I made it easy to query using dot notation, just like MongoDB.
- So, you can use `data.a`
- Multiple SQLite databases, with cloned schemas or different schemas. Strongly-typed in the IDE.## Usage
Please see [/tests/suites](https://github.com/patarapolw/liteorm/tree/master/tests/suites) and [ankisync.js](https://github.com/patarapolw/ankisync.js)
## Installation
```sh
npm i liteorm
# or yarn add liteorm
```## Caveats
- Type `Number` by default is associated with `REAL`. To change it to `INTEGER`, use
```ts
@prop({type: 'int'}) count!: number;
```- `BLOB` is associated with Type `ArrayBuffer`.
```ts
@prop() data!: ArrayBuffer;
```- To get a strongly-typed `default` / `onUpdate`, you might have to declare typing twice.
```ts
@prop>({ default: () => ({}) }) data!: Record;
@prop({ default: 1, onUpdate: (ent) => parseToInt(ent) }) order!: number;
```- You might have to declare your own interface to get keys for `createdAt`, `updatedAt`, because typing is based directly on Class.