Skip to content

Commit

Permalink
1.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
artegoser committed May 6, 2021
1 parent 25e3efa commit 37e0465
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
24 changes: 23 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class SqliteChatStorage {
* Select a message(s) by sql-query
* @param {string} what sql column
* @param {string|none} where sql condition
* @returns promise with sql response
* @returns promise(err|row)
*/
select(what, where){
if (where){
Expand Down Expand Up @@ -189,6 +189,19 @@ class SqliteChatStorage {
});
});
}
/**
* Runs the SQL query with the specified parameters.
* @param {string} query SQLite query
* @returns promise(err|row)
*/
sqlite_all(query){
return new Promise((res, rej)=>{
this._db.all(query, (err, row)=>{
if(err) rej(err);
else res(row);
});
});
}
/**
* Deletes a message by id
* @param {integer} id message id (constructor.messages[*].id)
Expand Down Expand Up @@ -240,6 +253,15 @@ class SqliteChatStorage {
set messages(v){
throw new Error("in sqlite chat storage you can't change the messages variable, you can only read it")
}
/**
* Get name of sqlite table
*/
get name(){
return this._name
}
set name(v){
throw new Error("in sqlite chat storage you can't change the name variable, you can only read it")
}
/**
* Get current time in format YYYY-MM-DD HH:MM:SS
*/
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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
Expand Up @@ -9,7 +9,7 @@
"coverage": "nyc npm test",
"coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls",
"docs": "jsdoc index.js -t docdash -d D:\\github\\artegoser.github.io\\simple-chat-storage\\documentation -r ./README.md",
"buildall":"npm run coveralls && npm run docs"
"buildall": "npm run coveralls && npm run docs"
},
"nyc": {
"exclude": "**/*.spec.js"
Expand Down
29 changes: 29 additions & 0 deletions tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ describe("sqlite",()=>{
throw new Error("no error occurred")
}
});
it("should throw error when name has been changed", ()=>{
let error = false;
try{
test.name = 0;
} catch{
error = true;
}
if(!error){
throw new Error("no error occurred")
}
});
describe(`sqlite select message`, ()=>{
it("should select all messages", ()=>{
return test.prepare().then(()=>{
Expand Down Expand Up @@ -170,6 +181,24 @@ describe("sqlite",()=>{
});
});
});
describe(`sqlite sqlite_all`, ()=>{
it("should select all messages", ()=>{
return test.prepare().then(()=>{
return test.sqlite_all(`SELECT * FROM ${test.name}`).then((val)=>{
if(val.length!==test.messages.length){
throw new Error("not all messages selected")
}
});
});
});
it("should throw error", ()=>{
return test.prepare().then(()=>{
return test.sqlite_all("err").then(null, (err)=>{
if(!err) throw new Error("no error occurred")
});
});
});
});
it("should replace message to HEllo lol", ()=>{
return test.prepare().then(()=>{
return test.addmessage("Cool", "not lol").then(()=>{
Expand Down

0 comments on commit 37e0465

Please sign in to comment.