Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/so1ve/dittorm-deno
[WIP] A Deno ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.
https://github.com/so1ve/dittorm-deno
deno deta leancloud orm
Last synced: 14 days ago
JSON representation
[WIP] A Deno ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.
- Host: GitHub
- URL: https://github.com/so1ve/dittorm-deno
- Owner: so1ve
- License: mit
- Created: 2022-03-04T13:36:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-10T04:56:22.000Z (almost 2 years ago)
- Last Synced: 2024-09-16T14:49:37.302Z (about 2 months ago)
- Topics: deno, deta, leancloud, orm
- Language: TypeScript
- Homepage: https://deno.land/x/dittorm
- Size: 45.9 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deta - dittorm-deno - A Deno ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud. (ORM's / JavaScript ORM)
README
# dittorm-deno
A Deno ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless
service like Deta, InspireCloud, CloudBase, LeanCloud. Ported from [walinejs/dittorm](https://github.com/walinejs/dittorm)> **WARNING**: Currently, only leancloud and deta are supported.
## Quick Start
```ts
import dittorm from "https://deno.land/x/dittorm/mod.ts";const userModel = dittorm("leancloud")("user", {
appId: "xxx",
appKey: "xxx",
masterKey: "xxx",
});
const user = await userModel.add({
username: "lizheming",
email: "[email protected]",
});
const findUser = await user.select({ email: "[email protected]" });
```## Documentation
### Configuration
#### LeanCloud
```ts
import dittorm from "https://deno.land/x/dittorm/mod.ts";const userModel = dittorm("leancloud")("user", {
appId: "xxx",
appKey: "xxx",
masterKey: "xxx",
});
```| Name | Required | Default | Description |
| ----------- | -------- | ------- | ----------- |
| `appId` | ✅ | | |
| `appKey` | ✅ | | |
| `masterKey` | ✅ | | |#### Deta
```ts
import dittorm from "https://deno.land/x/dittorm/mod.ts";const userModel = dittorm("deta")("user", {
projectKey: 'xxx'
});
```| Name | Required | Default | Description |
| ------- | -------- | ------- | ----------------------- |
| `projectKey` | ✅ | | Deta project secret key |TODO
### API
#### add(data)
Save store data.
```ts
const data = await userModel.add({
username: "lizheming",
email: "[email protected]",
});
console.log(data.id);
```#### select(where, options)
Find store data by condition.
```js
// SELECT * FROM user WHERE username = 'lizheming';
const data = await userModel.select({ username: "lizheming" });// SELECT email FROM user WHERE username = 'lizheming' ORDER BY email DESC LIMIT 1 OFFSET 1;
const data = await userModel.select({ username: "lizheming" }, {
field: ["email"],
desc: "email",
limit: 1,
offset: 1,
});// SELECT * FROM user WHERE username != 'lizheming';
const data = await userModel.select({ username: ["!=", "lizheming"] });// SELECT * FROM user WHERE create_time > '2022-01-01 00:00:00';
const data = await userModel.select({ username: [">", "2022-01-01 00:00:00"] });// SELECT * FROM user WHERE username IN ('lizheming', 'michael');
const data = await userModel.select({
username: ["IN", ["lizheming", "michael"]],
});// SELECT * FROM user WHERE username NOT IN ('lizheming', 'michael');
const data = await userModel.select({
username: ["NOT IN", ["lizheming", "michael"]],
});// SELECT * FROM user WHERE username LIKE '%li%';
const data = await userModel.select({ username: ["LIKE", "%li%"] });// SELECT * FROM user WHERE username = 'lizheming' AND create_time > '2022-01-01 00:00:00';
const data = await userModel.select({
username: "lizheming",
create_time: [">", "2022-01-01 00:00:00"],
});// SELECT * FROM user WHERE username = 'lizheming' OR create_time > '2022-01-01 00:00:00';
const data = await userModel.select({
_complex: {
username: "lizheming",
create_time: [">", "2022-01-01 00:00:00"],
_logic: "or",
},
});
```#### update(data, where)
Update store data by condition. `where` format same as `select(where, options)`.
#### count(where)
Return store data count by condition. `where` format same as
`select(where, options)`.#### delete(where)
Clean store data by condition. `where` format same as `select(where, options)`.
### Types
See [Here](./src/types.ts).