Skip to content

Commit

Permalink
2.1.4
Browse files Browse the repository at this point in the history
Adding format option in JSONDriver
  • Loading branch information
itsusif committed Mar 16, 2024
1 parent 73d4a54 commit 38488a7
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 16 deletions.
1 change: 1 addition & 0 deletions dist/Drivers/JSON.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { JSONDriverOptions } from '../Types';
export declare class JSONDriver {
readonly options?: JSONDriverOptions | undefined;
readonly path: string;
readonly format: boolean;
constructor(options?: JSONDriverOptions | undefined);
private checkFile;
init(table: string): void;
Expand Down
5 changes: 5 additions & 0 deletions dist/Drivers/JSON.js

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

2 changes: 1 addition & 1 deletion dist/Drivers/JSON.js.map

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

6 changes: 3 additions & 3 deletions dist/Drivers/SQLite.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { JSONDriverOptions } from '../Types';
import { SQLiteDriverOptions } from '../Types';
export declare class SQLiteDriver {
readonly options?: JSONDriverOptions | undefined;
readonly options?: SQLiteDriverOptions | undefined;
readonly path: string;
private db;
constructor(options?: JSONDriverOptions | undefined);
constructor(options?: SQLiteDriverOptions | undefined);
init(table: string): void;
setRowByKey(table: string, key: string, value: any): boolean;
getAllRows(table: string): any;
Expand Down
2 changes: 1 addition & 1 deletion dist/Drivers/SQLite.js.map

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

6 changes: 3 additions & 3 deletions dist/Drivers/YML.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JSONDriverOptions } from '../Types';
import { YMLDriverOptions } from '../Types';
export declare class YMLDriver {
readonly options?: JSONDriverOptions | undefined;
readonly options?: YMLDriverOptions | undefined;
readonly path: string;
constructor(options?: JSONDriverOptions | undefined);
constructor(options?: YMLDriverOptions | undefined);
private checkFile;
init(table: string): void;
setRowByKey(table: string, key: string, value: any): boolean;
Expand Down
2 changes: 1 addition & 1 deletion dist/Drivers/YML.js.map

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

7 changes: 7 additions & 0 deletions dist/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type goodDBOptions = {
};
export type JSONDriverOptions = {
path?: string;
format?: boolean;
};
export type methodOptions = {
nested?: string;
Expand All @@ -15,3 +16,9 @@ export interface MongoDBDriverOptions {
uri: string;
database?: string;
}
export type SQLiteDriverOptions = {
path?: string;
};
export type YMLDriverOptions = {
path?: string;
};
2 changes: 1 addition & 1 deletion dist/Types.js.map

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "good.db",
"version": "2.1.3",
"version": "2.1.4",
"description": "A simple, fast, and powerful database package for Node.js",
"main": "dist/index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/Drivers/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import fs from 'fs';

export class JSONDriver {
public readonly path: string;
public readonly format: boolean;

constructor(
public readonly options?: JSONDriverOptions
) {
this.path = options?.path || './db.json';
this.format = options?.format || false;
};

private checkFile(): boolean {
Expand Down Expand Up @@ -67,10 +69,14 @@ export class JSONDriver {
};

public write(data: any): boolean {
if (this.format) {
fs.writeFileSync(this.path, JSON.stringify(data, null, 2));
return true;
}
fs.writeFileSync(this.path, JSON.stringify(data));
return true;
};

public clear(): boolean {
this.write({});
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/SQLite.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { JSONDriverOptions } from '../Types';
import { SQLiteDriverOptions } from '../Types';
import Database, { Database as DataBaseType } from 'better-sqlite3';

export class SQLiteDriver {
public readonly path: string;
private db: DataBaseType;

constructor(public readonly options?: JSONDriverOptions) {
constructor(public readonly options?: SQLiteDriverOptions) {
this.path = options?.path || './db.sqlite';
this.db = new Database(this.path);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/YML.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fs from 'fs';
import yaml from 'js-yaml';
import { JSONDriverOptions } from '../Types';
import { YMLDriverOptions } from '../Types';

export class YMLDriver {
public readonly path: string;

constructor(
public readonly options?: JSONDriverOptions
public readonly options?: YMLDriverOptions
) {
this.path = options?.path || './db.yml';
};
Expand Down
9 changes: 9 additions & 0 deletions src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type goodDBOptions = {
export type JSONDriverOptions = {
// nested
path?: string;
format?: boolean;
};

export type methodOptions = {
Expand All @@ -30,4 +31,12 @@ export type methodOptions = {
export interface MongoDBDriverOptions {
uri: string; // MongoDB connection URI
database?: string; // MongoDB database name
};

export type SQLiteDriverOptions = {
path?: string;
};

export type YMLDriverOptions = {
path?: string;
};

0 comments on commit 38488a7

Please sign in to comment.