-
Notifications
You must be signed in to change notification settings - Fork 93
BUG: remove() does not delete data from the storage (PG) #105
Copy link
Copy link
Closed
Description
Reproduce
- Node.JS - 6.13.1
- Ueberdb2 - >=0.3.1 (and NOT on 0.3.0)
var ueberDB = require('ueberdb2');
var db = new ueberDB.database('postgres', {
host: 'localhost',
user: 'test',
password: 'test',
database: 'test'
});
//initialize the database
db.init(function (err) {
if (err) {
console.error(err);
process.exit(1);
}
//set a object as a value
//can be done without a callback, cause the value is immediately in the buffer
db.set('valueA', {
a: 1,
b: 2
});
//get the object
db.get('valueA', function (err, value) {
console.log('valueA before delete', value);
db.remove('valueA', function (err) {
if (err) {
console.log('Err deleting valueA', err);
}
db.get('valueA', function (err, value) {
console.log('valueA after delete', value);
db.close(function () {
process.exit(0);
});
});
});
});
});
Result
Console output:
valueA before delete { a: 1, b: 2 }
valueA after delete { a: 1, b: 2 }
Expected
Data not to be fount after delete.
valueA before delete { a: 1, b: 2 }
valueA after delete null
Cause
From PG logs I can see that the data is inserted into the database AFTER the DELETE statement is executed.
2018-03-22 12:31:09 EET LOG: statement: CREATE OR REPLACE FUNCTION ueberdb_insert_or_update(character varying, text) RETURNS void AS $$ BEGIN IF EXISTS( SELECT * FROM store WHERE key = $1 ) THEN UPDATE store SET value = $2 WHERE key = $1; ELSE INSERT INTO store(key,value) VALUES( $1, $2 ); END IF; RETURN; END; $$ LANGUAGE plpgsql;
2018-03-22 12:31:09 EET LOG: statement: SELECT 1 as exists FROM pg_tables WHERE tablename = 'store'
2018-03-22 12:31:09 EET LOG: execute <unnamed>: DELETE FROM store WHERE key=$1
2018-03-22 12:31:09 EET DETAIL: parameters: $1 = 'valueA'
2018-03-22 12:31:09 EET LOG: execute <unnamed>: SELECT ueberdb_insert_or_update($1,$2)
2018-03-22 12:31:09 EET DETAIL: parameters: $1 = 'valueA', $2 = '{"a":1,"b":2}'
I'm glad to get your insight and make a pull request once I know what to fix.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels