Skip to content

Commit

Permalink
chore: benchmark updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-online committed Apr 10, 2024
1 parent c8baf57 commit c01850b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
1 change: 1 addition & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"tinybench": "^2.6.0"
},
"devDependencies": {
"@types/node": "^20.12.7",
"tsup": "^8.0.2"
}
}
3 changes: 1 addition & 2 deletions benchmark/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Brine } from "../../dist";
import { Brine, BrineDatabases } from "../../dist";
import { Spinner } from "@favware/colorette-spinner";
import { BrineDatabases } from "../../src";
import { Bench } from "tinybench";

const randomData = (length: number) => {
Expand Down
2 changes: 0 additions & 2 deletions benchmark/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ export default defineConfig({
clean: true,
entryPoints: ["src/index.ts"],
format: ["cjs"],
// regex ends in .node
external: [/\.node$/],
});
30 changes: 15 additions & 15 deletions crates/migration/src/m20220101_000001_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Brine::Table)
.if_not_exists()
.col(ColumnDef::new(Brine::Key).string().not_null().primary_key())
.col(ColumnDef::new(Brine::Value).string())
.to_owned(),
)
.await
}
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(Brine::Table)
.if_not_exists()
.col(ColumnDef::new(Brine::Key).text().primary_key())
.col(ColumnDef::new(Brine::Value).text())
.to_owned(),
)
.await
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,5 @@
"typescript": "^5.4.4",
"vitest": "^1.4.0"
},
"packageManager": "[email protected]",
"optionalDependencies": {
"@brine-db/brine-win32-x64-msvc": "2.0.2-next",
"@brine-db/brine-darwin-x64": "2.0.2-next",
"@brine-db/brine-linux-x64-gnu": "2.0.2-next"
}
}
"packageManager": "[email protected]"
}
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export interface BrineOptions<T> {
class Brine<T = unknown> {
private db: BrineDb;

private deserialize: (value: string) => T | Promise<T> = JSON.parse;
private serialize: (value: T) => string | Promise<string> = JSON.stringify;
private internalDeserialize: (value: string) => T | Promise<T> = JSON.parse;
private internalSerialize: (value: T) => string | Promise<string> =
JSON.stringify;

/**
* Create a new Brine instance
Expand All @@ -49,11 +50,11 @@ class Brine<T = unknown> {
this.db = new BrineDb(connectionURI);

if (options?.serialize) {
this.serialize = options.serialize;
this.internalSerialize = options.serialize;
}

if (options?.deserialize) {
this.deserialize = options.deserialize;
this.internalDeserialize = options.deserialize;
}
}

Expand Down Expand Up @@ -239,6 +240,14 @@ class Brine<T = unknown> {
public async close() {
await this.db.close();
}

private async serialize(value: T): Promise<string> {
return this.internalSerialize(value);
}

private async deserialize(value: string): Promise<T> {
return this.internalDeserialize(value);
}
}

export { Brine };
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,15 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^20.12.7":
version: 20.12.7
resolution: "@types/node@npm:20.12.7"
dependencies:
undici-types: "npm:~5.26.4"
checksum: 10c0/dce80d63a3b91892b321af823d624995c61e39c6a223cc0ac481a44d337640cc46931d33efb3beeed75f5c85c3bda1d97cef4c5cd4ec333caf5dee59cff6eca0
languageName: node
linkType: hard

"@vitest/coverage-v8@npm:^1.4.0":
version: 1.4.0
resolution: "@vitest/coverage-v8@npm:1.4.0"
Expand Down Expand Up @@ -1055,6 +1064,7 @@ __metadata:
resolution: "brine-benchmark@workspace:benchmark"
dependencies:
"@favware/colorette-spinner": "npm:^1.0.1"
"@types/node": "npm:^20.12.7"
enmap: "npm:^6.0.0"
tinybench: "npm:^2.6.0"
tsup: "npm:^8.0.2"
Expand Down Expand Up @@ -3401,6 +3411,13 @@ __metadata:
languageName: node
linkType: hard

"undici-types@npm:~5.26.4":
version: 5.26.5
resolution: "undici-types@npm:5.26.5"
checksum: 10c0/bb673d7876c2d411b6eb6c560e0c571eef4a01c1c19925175d16e3a30c4c428181fb8d7ae802a261f283e4166a0ac435e2f505743aa9e45d893f9a3df017b501
languageName: node
linkType: hard

"unique-filename@npm:^3.0.0":
version: 3.0.0
resolution: "unique-filename@npm:3.0.0"
Expand Down

0 comments on commit c01850b

Please sign in to comment.