[chore] fmt readme
This commit is contained in:
parent
65a4f6c233
commit
8439e5b450
70
README.md
70
README.md
|
@ -4,10 +4,12 @@
|
|||
DAL is a proxy layer for SQL databases with a MongoDB inspired query interface.
|
||||
It can be used as a Go or NodeJS package (requires compiler) to create your own proxy and apply custom middlewares.
|
||||
|
||||
**Note:** This project is still in early alpha. You need to build it yourself and use at your own risk.
|
||||
**Note:** At the time only SQLite is implemented. However, other drivers might work.
|
||||
_Notes:_
|
||||
|
||||
**Use cases**
|
||||
- This project is still in early alpha. You need to build it yourself and use at your own risk.
|
||||
- At the time only SQLite is implemented, however, other drivers might work.
|
||||
|
||||
_Use cases:_
|
||||
|
||||
- For IOT networks when MySQL/PG are too heavy.
|
||||
- If you need a layer between your application and the database (i.e. for caching).
|
||||
|
@ -47,41 +49,41 @@ pnpm add git+git@github.com:nesterow/dal.git
|
|||
### Query Interface
|
||||
|
||||
| Method | Description | SQL |
|
||||
| ---------------------------------------------- | -------------------------------------- | ---------------------------------------------------- |
|
||||
| In(table: string) | Select table | `SELECT * FROM table` |
|
||||
| Find(filter: object) | Filter rows | `SELECT * FROM table WHERE filter` |
|
||||
| Fields(fields: string[]) | Select fields | `SELECT fields, FROM table` |
|
||||
| Sort(sort: string) | Sort rows | `SELECT * FROM table ORDER BY sort` |
|
||||
| Limit(limit: number) | Limit rows | `SELECT * FROM table LIMIT limit` |
|
||||
| Offset(offset: number) | Offset rows | `SELECT * FROM table OFFSET offset` |
|
||||
| Join({ $for: "table_2", $do: { "t.a": "b" } }) | Join tables | `SELECT * FROM table t JOIN table_2 ON t.a = b` |
|
||||
| Insert({name: "Julian"}, {name: "Bob"}) | Insert row | `INSERT INTO table (name,) VALUES ('Julian', 'Bob')` |
|
||||
| Set({name: "Julian"}) | Update row (Find(filter).Set({})) | `UPDATE table SET name = 'Julian' WHERE filter` |
|
||||
| Delete() | Delete row (Find(filter).Delete()) | `DELETE FROM table WHERE filter` |
|
||||
| As(DTO) | Map rows to a DTO | `SELECT * FROM table` |
|
||||
| Rows() | Get rows iterator | `SELECT * FROM table` |
|
||||
| Exec() | Execute query (update, insert, delete) | `SQL RESULT` |
|
||||
| Query() | Query database | DTO array |
|
||||
| Tx() | Run in trasaction | |
|
||||
| -------------------------------------------- | -------------------------------------- | ----------------------------------------------- |
|
||||
| `In(table: string)` | Select table | `SELECT * FROM table` |
|
||||
| `Find(filter: object)` | Filter rows | `SELECT * FROM table WHERE filter` |
|
||||
| `Fields(fields: string[])` | Select fields | `SELECT fields, FROM table` |
|
||||
| `Sort(sort)` | Sort rows | `SELECT * FROM table ORDER BY sort` |
|
||||
| `Limit(limit: number)` | Limit rows | `SELECT * FROM table LIMIT limit` |
|
||||
| `Offset(offset: number)` | Offset rows | `SELECT * FROM table OFFSET offset` |
|
||||
| `Join({ $for: "t_2", $do: { "t.a": "b" } })` | Join tables | `SELECT * FROM table t JOIN t_2 ON t.a = b` |
|
||||
| `Insert({name: "J"}, {name: "B"})` | Insert row | `INSERT INTO table (name,) VALUES ('J', 'B')` |
|
||||
| `Set({name: "Julian"})` | Update row (Find(filter).Set({})) | `UPDATE table SET name = 'Julian' WHERE filter` |
|
||||
| `Delete()` | Delete row (Find(filter).Delete()) | `DELETE FROM table WHERE filter` |
|
||||
| `As(DTO)` | Map rows to a DTO | `SELECT * FROM table` |
|
||||
| `Rows()` | Get rows iterator | `SELECT * FROM table` |
|
||||
| `Exec()` | Execute query (update, insert, delete) | `SQL RESULT` |
|
||||
| `Query()` | Query database | DTO array |
|
||||
| `Tx()` | Run in trasaction | |
|
||||
|
||||
### Filters
|
||||
|
||||
| Filter | Description | SQL |
|
||||
| --------------------------- | ---------------------- | ------------------------------ |
|
||||
| {id: 1, num: 2} | Equals, default filter | `WHERE id = 1 AND num = 2` |
|
||||
| {id: { $eq: 1 }} | Equals, explicit | `WHERE id = 1` |
|
||||
| {id: { $gt: 1 }} | Greater than | `WHERE id > 1` |
|
||||
| {id: { $gte: 1 }} | Greater than or equal | `WHERE id >= 1` |
|
||||
| {id: { $lt: 1 }} | Less than | `WHERE id < 1` |
|
||||
| {id: { $lte: 1 }} | Less than or equal | `WHERE id <= 1` |
|
||||
| {id: { $ne: 1 }} | Not equal | `WHERE id != 1` |
|
||||
| {id: { $in: [1, 2] }} | In | `WHERE id IN (1, 2)` |
|
||||
| {id: { $nin: [1, 2] }} | Not in | `WHERE id NOT IN (1, 2)` |
|
||||
| {id: { $like: "a" }} | Like | `WHERE id LIKE '%a%'` |
|
||||
| {id: { $nlike: "a" }} | Not like | `WHERE id NOT LIKE '%a%'` |
|
||||
| {id: { $between: [1, 2] }} | Between | `WHERE id BETWEEN 1 AND 2` |
|
||||
| {id: { $nbetween: [1, 2] }} | Not between | `WHERE id NOT BETWEEN 1 AND 2` |
|
||||
| {id: { $glob: "\*son" }} | Glob | `WHERE id GLOB '*son'` |
|
||||
| ----------------------------- | ---------------------- | ------------------------------ |
|
||||
| `{id: 1, num: 2}` | Equals, default filter | `WHERE id = 1 AND num = 2` |
|
||||
| `{id: { $eq: 1 }}` | Equals, explicit | `WHERE id = 1` |
|
||||
| `{id: { $gt: 1 }}` | Greater than | `WHERE id > 1` |
|
||||
| `{id: { $gte: 1 }}` | Greater than or equal | `WHERE id >= 1` |
|
||||
| `{id: { $lt: 1 }}` | Less than | `WHERE id < 1` |
|
||||
| `{id: { $lte: 1 }}` | Less than or equal | `WHERE id <= 1` |
|
||||
| `{id: { $ne: 1 }}` | Not equal | `WHERE id != 1` |
|
||||
| `{id: { $in: [1, 2] }}` | In | `WHERE id IN (1, 2)` |
|
||||
| `{id: { $nin: [1, 2] }}` | Not in | `WHERE id NOT IN (1, 2)` |
|
||||
| `{id: { $like: "a" }}` | Like | `WHERE id LIKE '%a%'` |
|
||||
| `{id: { $nlike: "a" }}` | Not like | `WHERE id NOT LIKE '%a%'` |
|
||||
| `{id: { $between: [1, 2] }}` | Between | `WHERE id BETWEEN 1 AND 2` |
|
||||
| `{id: { $nbetween: [1, 2] }}` | Not between | `WHERE id NOT BETWEEN 1 AND 2` |
|
||||
| `{id: { $glob: "\*son" }}` | Glob | `WHERE id GLOB '*son'` |
|
||||
|
||||
### Example
|
||||
|
||||
|
|
Loading…
Reference in a new issue