[chore] format ts
Signed-off-by: Anton Nesterov <anton@demiurg.io>
This commit is contained in:
parent
0cecd1243f
commit
60d213f21c
15
README.md
15
README.md
|
@ -5,17 +5,14 @@ Data Accees Layer for SQL databases written in Go.
|
|||
Mongodb inspired query interface:
|
||||
|
||||
```typescript
|
||||
const query = Db
|
||||
.In("users")
|
||||
const query = Db.In("users")
|
||||
.Find({
|
||||
fullname: { $glob: "*son" }
|
||||
fullname: { $glob: "*son" },
|
||||
})
|
||||
.Query()
|
||||
.Query();
|
||||
|
||||
// Result:
|
||||
console.log(users)
|
||||
[
|
||||
{ id: 25, fullname: "John Menson" },
|
||||
{ id: 76, fullname: "John Johnson" }
|
||||
]
|
||||
console.log(users)[
|
||||
({ id: 25, fullname: "John Menson" }, { id: 76, fullname: "John Johnson" })
|
||||
];
|
||||
```
|
|
@ -36,10 +36,7 @@ type Options = {
|
|||
url: string;
|
||||
};
|
||||
|
||||
|
||||
export default class Builder <
|
||||
I extends abstract new (...args: any) => any,
|
||||
>{
|
||||
export default class Builder<I extends abstract new (...args: any) => any> {
|
||||
private request: Request;
|
||||
private url: string;
|
||||
private dtoTemplate: new (...args: any) => any = Object;
|
||||
|
@ -54,14 +51,14 @@ I extends abstract new (...args: any) => any,
|
|||
this.url = opts.url;
|
||||
}
|
||||
private formatRequest(): void {
|
||||
this.request.commands = []
|
||||
this.request.commands = [];
|
||||
METHODS.forEach((method) => {
|
||||
const args = this.methodCalls.get(method);
|
||||
if (!args) {
|
||||
return;
|
||||
}
|
||||
this.request.commands.push({ method, args });
|
||||
})
|
||||
});
|
||||
}
|
||||
private formatRow(data: unknown[]) {
|
||||
if (!this.dtoTemplate) {
|
||||
|
@ -175,7 +172,6 @@ I extends abstract new (...args: any) => any,
|
|||
for await (const row of rows) {
|
||||
result.push(row);
|
||||
}
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { encode, decode } from '@msgpack/msgpack';
|
||||
import { encode, decode } from "@msgpack/msgpack";
|
||||
|
||||
export interface Method {
|
||||
method: string;
|
||||
|
@ -11,7 +11,10 @@ export interface Request {
|
|||
commands: Method[];
|
||||
}
|
||||
|
||||
export const METHODS = "In|Find|Select|Fields|Join|Group|Sort|Limit|Offset|Delete|Insert|Set|Update|OnConflict|DoUpdate|DoNothing".split("|");
|
||||
export const METHODS =
|
||||
"In|Find|Select|Fields|Join|Group|Sort|Limit|Offset|Delete|Insert|Set|Update|OnConflict|DoUpdate|DoNothing".split(
|
||||
"|",
|
||||
);
|
||||
|
||||
export function encodeRequest(request: Request): Uint8Array {
|
||||
return encode(request);
|
||||
|
@ -31,7 +34,7 @@ export function decodeRows(input: Uint8Array): Row[] {
|
|||
if (input.at(count) != 0x81) {
|
||||
buf.push(input.at(count));
|
||||
count++;
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
const [a, b, c] = ROW_TAG;
|
||||
const [aa, bb, cc] = input.slice(count, count + 4);
|
||||
|
@ -49,7 +52,9 @@ export function decodeRows(input: Uint8Array): Row[] {
|
|||
return rows.map((row) => decode(new Uint8Array(row as number[]))) as Row[];
|
||||
}
|
||||
|
||||
export async function *decodeRowsIterator(stream: ReadableStream<Uint8Array>): AsyncGenerator<Row> {
|
||||
export async function* decodeRowsIterator(
|
||||
stream: ReadableStream<Uint8Array>,
|
||||
): AsyncGenerator<Row> {
|
||||
const reader = stream.getReader();
|
||||
let buf = new Uint8Array();
|
||||
for (;;) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { test, expect } from "bun:test";
|
||||
import { DAL } from ".."
|
||||
import { DAL } from "..";
|
||||
|
||||
const options = {
|
||||
database: "test.sqlite",
|
||||
url: "http://localhost:8111",
|
||||
}
|
||||
};
|
||||
|
||||
class DTO {
|
||||
id: number = 0;
|
||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
|||
export { default as DAL } from './Builder';
|
||||
export { default as DAL } from "./Builder";
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# [wip] DAL
|
||||
NodeJS Client for the [DAL]() Server.
|
||||
|
||||
NodeJS Client for the [DAL]() Server.
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
"module": "dal/index.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
"@types/bun": "latest",
|
||||
"prettier": "^3.3.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
|
@ -14,6 +15,7 @@
|
|||
"scripts": {
|
||||
"test:client": "bun test:*",
|
||||
"test:dal": "bun test dal/__test__",
|
||||
"test:serve": "cd dal/__test__/srv && go run main.go"
|
||||
"test:serve": "cd dal/__test__/srv && go run main.go",
|
||||
"fmt": "prettier --write ."
|
||||
}
|
||||
}
|
|
@ -2,17 +2,19 @@
|
|||
import { encode } from "https://deno.land/x/msgpack@v1.2/mod.ts";
|
||||
|
||||
const Query = {
|
||||
"db": "database.sqlite",
|
||||
"commands": [
|
||||
{"method": "In", "args": ["data"]},
|
||||
db: "database.sqlite",
|
||||
commands: [
|
||||
{ method: "In", args: ["data"] },
|
||||
{
|
||||
"method": "Find",
|
||||
"args": [{
|
||||
"a": 1,
|
||||
"b": {
|
||||
"$gt": 2,
|
||||
method: "Find",
|
||||
args: [
|
||||
{
|
||||
a: 1,
|
||||
b: {
|
||||
$gt: 2,
|
||||
},
|
||||
}]
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue