Skip to content

Commit

Permalink
👨‍💻CODE BY 🕊️★⃝AJAY O S©️🧚‍♂️
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajayos committed Apr 29, 2023
1 parent 5d3c8e5 commit e3e9542
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Dependency directories
node_modules/
jspm_packages/
jspm_packages/

.npmrc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { setDB, getDB, deleteDB } from '@ajayos/nodedb';
```
Then you can use the following functions:
`setDB(tableName: string, rowName: string, data: any): Promise<boolean>`
`setDB(tableName: string, rowName: string, data: any): Promise<any>`
Inserts or updates a row in the specified table with the specified key and data.
Expand Down
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteDB = exports.getDB = exports.setDB = void 0;
exports.deleteDB = exports.getDB = exports.setDB = exports.db = exports.allAsync = exports.runAsync = void 0;
var fs = require("fs");
var path = require("path");
var sqlite3 = require("sqlite3");
var util_1 = require("util");
var nodelog = require('@ajayos/nodelog');
var nodelog = require("@ajayos/nodelog");
var DB_FOLDER = 'DB';
var DB_FILE = 'ajayos.sql';
var DB_PATH = './' + DB_FOLDER + '/' + DB_FILE;
Expand All @@ -61,14 +61,17 @@ var db = new sqlite3.Database(DB_PATH, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CRE
log(err.message, 'error');
}
else {
log("Connected to the '".concat(DB_FILE, "' database."), 'info');
log("Connected to the database.", 'info');
}
});
}
});
exports.db = db;
// Promisify the db.run() and db.all() methods for easier use with async/await
var runAsync = (0, util_1.promisify)(db.run.bind(db));
exports.runAsync = runAsync;
var allAsync = (0, util_1.promisify)(db.all.bind(db));
exports.allAsync = allAsync;
// Create the 'setDB' function
var setDB = function (tableName, rowName, data) { return __awaiter(void 0, void 0, void 0, function () {
var result, result_1, err_1;
Expand Down
6 changes: 3 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const db = new sqlite3.Database(DB_PATH, sqlite3.OPEN_READWRITE | sqlite3.OPEN_C
if (err) {
log(err.message, 'error');
} else {
log(`Connected to the '${DB_FILE}' database.`, 'info');
log(`Connected to the database.`, 'info');
}
});
}
Expand All @@ -33,9 +33,9 @@ const db = new sqlite3.Database(DB_PATH, sqlite3.OPEN_READWRITE | sqlite3.OPEN_C
// Promisify the db.run() and db.all() methods for easier use with async/await
const runAsync = promisify(db.run.bind(db));
const allAsync = promisify(db.all.bind(db));

export { runAsync, allAsync, db };
// Create the 'setDB' function
export const setDB = async (tableName: string, rowName: string, data: any): Promise<boolean> => {
export const setDB = async (tableName: string, rowName: string, data: any): Promise<any> => {
try {
// Check if the table exists
const result = await allAsync(`SELECT name FROM sqlite_master WHERE type='table' AND name='${tableName}';`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ajayos/nodedb",
"version": "1.0.1",
"version": "1.0.3",
"description": "Database for nodejs",
"main": "index.js",
"ts": "index.ts",
Expand Down

0 comments on commit e3e9542

Please sign in to comment.