Skip to content

Commit

Permalink
Added rusty db (#742)
Browse files Browse the repository at this point in the history
* Added rusty db

* Added rusty db to tests.

---------

Co-authored-by: SamTV12345 <[email protected]>
  • Loading branch information
SamTV12345 and SamTV12345 authored Sep 5, 2024
1 parent 4f9b0fa commit 80c8479
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
db: [couch, elasticsearch, mongo, mysql, redis, mock, sqlite, redis, memory]
db: [couch, elasticsearch, mongo, mysql, redis, mock, sqlite, redis, memory, rusty]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
25 changes: 19 additions & 6 deletions databases/rusty_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import AbstractDatabase from "../lib/AbstractDatabase";
import {KeyValueDB} from "rusty-store-kv";

export default class Rusty_db extends AbstractDatabase {
db: KeyValueDB|null
db: KeyValueDB | null | undefined


constructor(settings: {filename: string}) {
super(settings);
this.db = new KeyValueDB(this.settings.filename!);

// set default settings
this.settings.cache = 0;
Expand All @@ -24,23 +23,37 @@ export default class Rusty_db extends AbstractDatabase {
}

get(key: string) {
return this.db!.get(key);
const val = this.db!.get(key);
if (!val) {
return val
}
try {
return JSON.parse(val)
} catch (e) {
return val
}
}

async init() {
console.log("Init")
this.db = new KeyValueDB(this.settings.filename!);
}

close() {

this.db?.close()
this.db = null
}

remove(key: string) {
this.db!.remove(key);
}

set(key: string, value: string) {
this.db!.set(key, value);
if (typeof value === "object") {
const valStr = JSON.stringify(value)
this.db!.set(key, valStr);
} else {
this.db!.set(key, value.toString());
}
}

destroy() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"rethinkdb": "^2.4.2",
"rollup": "^4.21.2",
"rollup-plugin-typescript2": "^0.36.0",
"rusty-store-kv": "^1.1.2",
"rusty-store-kv": "^1.1.4",
"semver": "^7.6.3",
"simple-git": "^3.26.0",
"surrealdb.js": "^0.11.1",
Expand Down
114 changes: 57 additions & 57 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions test/cassandra/test.cassandra.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {afterAll, beforeAll, describe} from "vitest";
import {test_db} from "../lib/test_lib";
import {GenericContainer, PortWithOptionalBinding, StartedTestContainer} from "testcontainers";

describe('cassandra test', ()=>{
const portMappings: PortWithOptionalBinding[] = [
{ container: 9042, host: 9042 },
{container: 10000, host: 10000}
];
let container: StartedTestContainer

beforeAll(async () => {
container = await new GenericContainer("scylladb/scylla:latest")
.withCommand([" --smp 1"])
.withExposedPorts(...portMappings)
.start()
})


test_db('cassandra')

afterAll(async () => {
await container.stop()
})
})
12 changes: 10 additions & 2 deletions test/lib/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const databases:DatabaseType = {
rustydb: {
filename: `${os.tmpdir()}/rusty.db`,
speeds: {
setMax: 0.6,
setMax: 2,
getMax: 0.5,
findKeysMax: 2.5,
removeMax: 0.5,
removeMax: 3,
},
},
mysql: {
Expand Down Expand Up @@ -91,5 +91,13 @@ export const databases:DatabaseType = {
speeds: {
findKeysMax: 30,
},
},
cassandra: {
columnFamily: 'test',
clientOptions: {
contactPoints: ['h1', 'h2'],
localDataCenter: 'datacenter1',
keyspace: 'ks1'
}
}
};
Loading

0 comments on commit 80c8479

Please sign in to comment.