Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
26 changes: 13 additions & 13 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"newline-before-return": true,
"no-duplicate-variable": [
true,
"check-parameters"
],
"no-var-keyword": true
}
{
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"newline-before-return": true,
"no-duplicate-variable": [
true,
"check-parameters"
],
"no-var-keyword": true
}
744 changes: 372 additions & 372 deletions LICENSE

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# bdb
ruben pls update
<<<<<<< HEAD
# bdb
ruben pls update
=======
# bdb
ruben pls update
>>>>>>> 0673c2c2b2c4388d12e104e7b0a501ad02bfba45
1 change: 1 addition & 0 deletions constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_TABLE = "DEFAULT_BYTE_TABLE"
22 changes: 11 additions & 11 deletions lib/core/ByteDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { DefaultByteProperties } from '../typings/types/DBP';
import { Events } from "../typings/interfaces/Events";
// structures
import { RowManager } from "../structures/RowManager";
import { DEFAULT_TABLE } from "../../constants";
// definitions
const deftable = { table: "DEFAULT_BYTE_TABLE" };

export class ByteDatabase extends Emitter<Events> {
/**
Expand All @@ -28,7 +28,7 @@ export class ByteDatabase extends Emitter<Events> {
* @property rows
* row handler for the database
*/
private rows: any = new RowManager(this)
private rows: RowManager = new RowManager(this)
/**
*
* @param paths
Expand All @@ -42,7 +42,7 @@ export class ByteDatabase extends Emitter<Events> {
this.raw = new Database(path, props)
}

public insert(key: string, val: any, table: any = deftable) {
public insert(key: string, val: string, table: string = DEFAULT_TABLE) {
if(typeof key !== "string") throw new ByteError("INVALID_TYPE", `Expected a type of string in method "INSERT". Recieved a type of ${typeof key} instead. \n If you need help, consider joining our Discord Server!: https://join.cloudteam.me`);
if(val === null) throw new ByteError("MISSING_ARGUMENT", `Expected 2 arguments in method "INSERT" . \n If you need help, consider joining our Discord Server!: https://join.cloudteam.me`);

Expand All @@ -52,39 +52,39 @@ export class ByteDatabase extends Emitter<Events> {
let got = this.find(ParentKey);
let _ = set(got ?? {}, splitted.slice(1).join("."), val);

return this.rows.insertRowByKey(ParentKey, _, table.table);
return this.rows.insertRowByKey(ParentKey, _, table);
} else {
let got = this.find(key);
let _ = set(got ?? {}, key, val);

return this.rows.insertRowByKey(key, _, table.table);
return this.rows.insertRowByKey(key, _, table);
}
}

public find(key: any, table: any = deftable) {
public find(key: string, table: string = DEFAULT_TABLE) {
if(typeof key !== "string") throw new ByteError("INVALID_TYPE", `Expected a type of string in method "INSERT". Recieved a type of ${typeof key} instead. \n If you need help, consider joining our Discord Server!: https://join.cloudteam.me`);
if(!key.includes(".")){
let result = this.rows.findRowByKey(key, table.table);
let result = this.rows.findRowByKey(key, table);
let _ = get(result, key);
return _
} else {
let splitted = key.split(".");
let ParentKey = splitted[0];

const result = this.rows.findRowByKey(ParentKey, table.table);
const result = this.rows.findRowByKey(ParentKey, table);
let _ = get(result, splitted.slice(1).join("."));
return _
}
}

public wipe(table: any = deftable) {
return this.rows.deleteAllRows(table.table)
public wipe(table: string = DEFAULT_TABLE) {
return this.rows.deleteAllRows(table)
}

public connect(): void{
console.log(`${chalk.green.bold("[ByteDatabase (Connection)]:")} Initializing default table...`)
try {
this.raw.prepare(`CREATE TABLE IF NOT EXISTS ${deftable.table} (ID TEXT, Json TEXT)`)
this.raw.prepare(`CREATE TABLE IF NOT EXISTS ${DEFAULT_TABLE} (ID TEXT, Json TEXT)`)
.run()
console.log(`${chalk.green.bold("[ByteDatabase (Connection)]:")} Successfully initialized default table.`)
} catch(error) {
Expand Down
12 changes: 6 additions & 6 deletions lib/structures/RowManager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { DEFAULT_TABLE } from "../../constants";
import { ByteDatabase } from "../core/ByteDatabase";
import { sanitize } from "../functions/sanitize";
var deftable = "DEFAULT_BYTE_TABLE"

export class RowManager {
database: any
database: ByteDatabase
constructor(db: ByteDatabase){
this.database = db
}

insertRowByKey(
key: string,
value: any,
table: any = deftable
table: string = DEFAULT_TABLE
){
const strjson = JSON.stringify(value);
const q = sanitize(`INSERT INTO ${table} (ID,Json) VALUES (?,?)`);
Expand All @@ -21,7 +21,7 @@ export class RowManager {
updateRowByKey(
key: string,
value: any,
table: any = deftable
table: string = DEFAULT_TABLE
){
const strjson = JSON.stringify(value);

Expand All @@ -33,15 +33,15 @@ export class RowManager {

findRowByKey(
key: string,
table: any = deftable
table: string = DEFAULT_TABLE
){
let q = sanitize(`SELECT Json FROM ${table} WHERE ID = @key`)
let val = this.database.raw.prepare(q).get({ key })
return val != null ? JSON.parse(val.Json) : null;
}

deleteAllRows(
table: any = deftable
table: string = DEFAULT_TABLE
){
return this.database.raw.prepare(`DELETE FROM ${table}`).run().changes;
}
Expand Down
30 changes: 15 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"compilerOptions":{
"target":"ESNext",
"experimentalDecorators":true,
"module":"CommonJS",
"rootDir":".",
"resolveJsonModule":true,
"outDir":"dist",
"esModuleInterop":true,
"forceConsistentCasingInFileNames":true,
"strict":true,
"skipLibCheck":true,
"noImplicitAny":true,
"suppressImplicitAnyIndexErrors": true
}
{
"compilerOptions":{
"target":"ESNext",
"experimentalDecorators":true,
"module":"CommonJS",
"rootDir":".",
"resolveJsonModule":true,
"outDir":"dist",
"esModuleInterop":true,
"forceConsistentCasingInFileNames":true,
"strict":true,
"skipLibCheck":true,
"noImplicitAny":true,
"suppressImplicitAnyIndexErrors": true
}
}