Skip to content

Commit

Permalink
fix delete on lmdb/sql
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeTWC1984 committed Mar 22, 2024
1 parent 19acd9d commit 7912cbd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
7 changes: 4 additions & 3 deletions engines/Lmdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ module.exports = class LmdbEngine extends Component {
}


async delete(key, callback) {
// delete LevelDb key given key
var self = this;
async delete(key, callback) {

const self = this;

key = this.prepKey(key);

this.logDebug(9, "Deleting LevelDb Object: " + key);
Expand Down
33 changes: 20 additions & 13 deletions engines/SQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const Component = require("pixl-server/component");
const { knex, Knex } = require('knex')
const { Readable } = require('stream');

class NoSuchKeyError extends Error {
constructor(key = 'key', crudOp = 'Fetch') {
super(`Failed to ${crudOp} key: ${key}: Not found`)
}
code = "NoSuchKey"
}

module.exports = class SQLEngine extends Component {

__name = 'SQLEngine'
Expand Down Expand Up @@ -212,9 +219,9 @@ module.exports = class SQLEngine extends Component {
callback(null, rows[0]);
}
else {
let err = new Error("Failed to head key: " + key + ": Not found");
err.code = "NoSuchKey";
callback(err, null);
// let err = new Error("Failed to head key: " + key + ": Not found");
// err.code = "NoSuchKey";
callback(new NoSuchKeyError(key, 'head') , null);
}

}
Expand Down Expand Up @@ -254,9 +261,9 @@ module.exports = class SQLEngine extends Component {
}
}
else {
let err = new Error("Failed to fetch key: " + key + ": Not found");
err.code = "NoSuchKey";
callback(err, null);
// let err = new Error("Failed to fetch key: " + key + ": Not found");
// err.code = "NoSuchKey";
callback(new NoSuchKeyError(key, 'fetch'), null);
}

}
Expand Down Expand Up @@ -284,9 +291,9 @@ module.exports = class SQLEngine extends Component {
}
else if (!buf) {
// record not found
let ERR = new Error("Failed to fetch key: " + key + ": Not found");
ERR.code = "NoSuchKey";
return callback(ERR, null);
// let ERR = new Error("Failed to fetch key: " + key + ": Not found");
// ERR.code = "NoSuchKey";
return callback(new NoSuchKeyError(key, 'fetch'), null);
}

let stream = Readable.from(buf) // new BufferStream(buf);
Expand All @@ -310,9 +317,9 @@ module.exports = class SQLEngine extends Component {
}
else if (!buf) {
// record not found
let ERR = new Error("Failed to fetch key: " + key + ": Not found");
ERR.code = "NoSuchKey";
return callback(ERR, null);
// let ERR = new Error("Failed to fetch key: " + key + ": Not found");
// ERR.code = "NoSuchKey";
return callback(new NoSuchKeyError(key, 'fetch'), null);
}

// validate byte range, now that we have the head info
Expand Down Expand Up @@ -346,7 +353,7 @@ module.exports = class SQLEngine extends Component {

try {
let d = await db(this.tableName).where('K', key).del()
delError = d > 0 ? self.logDebug(9, "Delete complete: " + key) : new Error("Failed to fetch key: " + key + ": Not found");
delError = d > 0 ? self.logDebug(9, "Delete complete: " + key) : new NoSuchKeyError(key, 'fetch')
}
catch (err) {
self.logError('sql', "Failed to delete object: " + key + ": " + err);
Expand Down

0 comments on commit 7912cbd

Please sign in to comment.