Skip to content

Commit

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

* Externalize rusty-store-kv

* Added close and init functions

* Added matrix

* Removed lint

* Fixed mysql

* Increased timeout

* Fixed.

* Fixed it.

* Removed postgresql

* Fixed elasticsearch
  • Loading branch information
SamTV12345 authored Sep 4, 2024
1 parent c798d0d commit 5607409
Show file tree
Hide file tree
Showing 34 changed files with 1,585 additions and 573 deletions.
73 changes: 8 additions & 65 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,12 @@ on:
jobs:
test:
runs-on: ubuntu-latest
services:
couchdb:
image: couchdb
ports:
- 5984:5984
env:
COUCHDB_USER: ueberdb
COUCHDB_PASSWORD: ueberdb
elasticsearch:
image: elasticsearch:7.17.3
ports:
- 9200:9200
env:
discovery.type: single-node
mongo:
image: mongo
ports:
- 27017:27017
mysql:
# The default authentication used in MySQL 8.0 isn't supported by the
# mysql npm package: https://github.com/mysqljs/mysql/issues/2002
image: mariadb
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: ueberdb
MYSQL_PASSWORD: ueberdb
MYSQL_DATABASE: ueberdb
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: ueberdb
POSTGRES_PASSWORD: ueberdb
POSTGRES_DB: ueberdb
options: >-
--health-cmd="pg_isready -d postgresql://ueberdb:[email protected]/ueberdb"
--health-interval=10s
--health-timeout=5s
--health-retries=5
redis:
image: redis
ports:
- 6379:6379
timeout-minutes: 30
strategy:
matrix:
db: [couch, elasticsearch, mongo, mysql, redis, mock, sqlite, redis, memory]
steps:
- uses: actions/checkout@v4
-
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
Expand All @@ -78,23 +33,11 @@ jobs:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- run: pnpm i

# Verify databases are reachable.
- name: MySQL client and server check
run: |
mysql --version &&
mysql -h 127.0.0.1 -u ueberdb -pueberdb -e "SHOW TABLES;" ueberdb
- name: PostgreSQL client and server check
run: |
psql --version &&
psql -d postgresql://ueberdb:[email protected]/ueberdb -c '\dt'
- name: Create javascript files from typescript
run: pnpm run build
- run: pnpm run test
env:
SURREALDB_CI: false
- run: pnpm run lint
name: Install pnpm dependencies
- run: pnpm run test ${{ matrix.db }}

publish-npm:
if: github.event_name == 'push'
Expand Down
49 changes: 49 additions & 0 deletions databases/rusty_db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import AbstractDatabase from "../lib/AbstractDatabase";
import {KeyValueDB} from "rusty-store-kv";

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


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

// set default settings
this.settings.cache = 0;
this.settings.writeInterval = 0;
this.settings.json = false;
}

get isAsync() {
return true;
}

findKeys(key: string, notKey?:string) {
return this.db!.findKeys(key, notKey);
}

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

async init() {
console.log("Init")
}

close() {

}

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

set(key: string, value: string) {
this.db!.set(key, value);
}

destroy() {
this.db!.destroy();
}
}
31 changes: 27 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,32 @@ import RedisDB from './databases/redis_db'
import Rethink_db from './databases/rethink_db'
import SQLiteDB from './databases/sqlite_db'
import SurrealDB from './databases/surrealdb_db'
import Rusty_db from "./databases/rusty_db";

type CBDBType = {
[key: string]:Function
}


export type DatabaseType =
| 'mysql'
| 'postgres'
| 'sqlite'
| 'rustydb'
| 'mongodb'
| 'redis'
| 'cassandra'
| 'dirty'
| 'dirtygit'
| 'elasticsearch'
| 'memory'
| 'mock'
| 'mssql'
| 'postgrespool'
| 'rethink'
| 'couch'
| 'surrealdb';

const cbDb: CBDBType= {
init: () => {},
flush: () => {},
Expand All @@ -66,7 +87,7 @@ const makeDoneCallback = (callback: (err?:any)=>{}, deprecated:(err:any)=>{}) =>
};

export class Database {
public readonly type: any;
public readonly type: DatabaseType;
public readonly dbSettings: any;
public readonly wrapperSettings: any | {};
public readonly logger: Function | null;
Expand All @@ -81,7 +102,7 @@ export class Database {
* from another logging library should also work, but performance may be reduced if the logger
* object does not have is${Level}Enabled() methods (isDebugEnabled(), etc.).
*/
constructor(type: undefined | string, dbSettings: Settings | null | string, wrapperSettings?: null | {}, logger: any = null) {
constructor(type: undefined | DatabaseType, dbSettings: Settings | null | string, wrapperSettings?: null | {}, logger: any = null) {
if (!type) {
type = 'sqlite';
dbSettings = null;
Expand All @@ -99,7 +120,7 @@ export class Database {
/**
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
*/
async init(callback = null) {
init(callback = null) {
const db:any = this.initDB();
db.logger = this.logger;
this.db = new DatabaseCache(db, this.wrapperSettings, this.logger);
Expand All @@ -118,6 +139,8 @@ export class Database {
return new Postgres_db(this.dbSettings);
case 'sqlite':
return new SQLiteDB(this.dbSettings);
case 'rustydb':
return new Rusty_db(this.dbSettings);
case 'mongodb':
return new Mongodb_db(this.dbSettings);
case 'redis':
Expand Down Expand Up @@ -191,7 +214,7 @@ export class Database {
* @param notKey
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
*/
findKeys(key:string, notKey:string, callback = null) {
findKeys(key:string, notKey?:string, callback = null) {
if (callback != null) { // @ts-ignore
return cbDb.findKeys.call(this.db, key, notKey, callback);
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
"rethinkdb": "^2.4.2",
"rollup": "^4.21.2",
"rollup-plugin-typescript2": "^0.36.0",
"rusty-store-kv": "^1.1.2",
"semver": "^7.6.3",
"simple-git": "^3.26.0",
"surrealdb.js": "^0.11.1",
"testcontainers": "^10.13.0",
"typescript": "^5.5.4",
"vitest": "^2.0.5",
"wtfnode": "^0.9.3"
Expand Down
Loading

0 comments on commit 5607409

Please sign in to comment.