[chore] format ts

Signed-off-by: Anton Nesterov <anton@demiurg.io>
This commit is contained in:
Anton Nesterov 2024-08-15 15:04:44 +02:00
parent 0cecd1243f
commit 60d213f21c
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5
10 changed files with 282 additions and 280 deletions

View file

@ -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" })
];
```

BIN
bun.lockb

Binary file not shown.

View file

@ -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,16 +51,16 @@ 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[]){
private formatRow(data: unknown[]) {
if (!this.dtoTemplate) {
return data;
}
@ -175,7 +172,6 @@ I extends abstract new (...args: any) => any,
for await (const row of rows) {
result.push(row);
}
return result
return result;
}
}

View file

@ -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 (;;) {

View file

@ -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.

View file

@ -1 +1 @@
export { default as DAL } from './Builder';
export { default as DAL } from "./Builder";

View file

@ -1,3 +1,3 @@
# [wip] DAL
NodeJS Client for the [DAL]() Server.
NodeJS Client for the [DAL]() Server.

View file

@ -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"
@ -13,7 +14,8 @@
},
"scripts": {
"test:client": "bun test:*",
"test:dal" : "bun test dal/__test__",
"test:serve": "cd dal/__test__/srv && go run main.go"
"test:dal": "bun test dal/__test__",
"test:serve": "cd dal/__test__/srv && go run main.go",
"fmt": "prettier --write ."
}
}

View file

@ -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,
},
}]
},
],
},
],
};