Google it?
Nope nvm got a prob again.
Itās not on google >:(
SO thinks that people are question banned will never change, so they usually donāt do much.
Itās sad, because so many places on the web are like an aristocratic government - they give love to the popular and clean and disregard the rest.
So I asked a few bad questions, so what?
Most of the others just simply have 0 votes.
Oh well, thatās what I get for expecting the internet to be a helpful place
(it is, but sometimes it isnāt)
whatās your question?
Ur the āJS queenā⦠help me out here!
const { indexedDB } = globalThis;
const awaitEvent = (obj, handlerName, rejOnError = true, timeout = Infinity, callback = () => {}) => {
if("object" !== typeof obj){
throw new TypeError(`Argument provided for object to bind the listener to is not of type "object".`);
}
if("string" !== typeof handlerName){
throw new TypeError(`Argument provided for object's event listener name is not of type "string".`);
}
if("function" !== typeof obj.addEventListener){
throw new TypeError(`Object does not have an "addEventListener" function.`);
}
if("function" !== typeof callback){
throw new TypeError(`Callback provided is not a function.`);
}
/*Status codes:
0: ok
1: timed out
*/
return new Promise((res, rej) => {
obj.addEventListener(handlerName, evt => {
callback(evt);
res({
"ok": true,
"status": 0,
"statusText": ""
});
});
if(timeout !== Infinity && timeout > 0){
globalThis.setTimeout(timeout, () => {
if(rejOnError){
rej({
"ok": false,
"status": 1,
"statusText": ""
});
}
else{
res({
"ok": false,
"status": 1,
"statusText": ""
});
}
});
}
});
};
const transactions = class {
constructor() {
this.db = null;
}
connect(name, version, upgradeNeededCallback = () => {}) {
if(this.db !== null){
throw new Error(`Database is already open. Close it using "disconnect()".`);
}
if("string" !== typeof name){
throw new TypeError(`Argument provided for the database name is not of type "string".`);
}
if("number" !== typeof version){
throw new TypeError(`Argument provided for the version is not of type "number".`);
}
if(version < 1){
throw new TypeError(`Database version cannot be less than one. Expected a greater-than 0 value, got a less-than 0 value of ${version} instead.`);
}
if("function" !== typeof upgradeNeededCallback){
throw new TypeError(`Argument provided for the upgrade needed callback is not a function.`);
}
return new Promise(async (res, rej) => {
const dEntries = await indexedDB.databases();
if(dEntries.filter(dEntry => dEntry.name === name).length < 1){
rej(new Error(`Database is not initialized. Use "create()" instead.`));
return;
}
const req = indexedDB.open(name, version);
req.addEventListener("success", () => {
this.db = req.result;
res(this.db);
});
req.addEventListener("upgradeneeded", event => {
this.db = req.result;
upgradeNeededCallback(event, this.db);
res(this.db);
});
req.addEventListener("error", err => rej(err));
});
}
create(name, createdCallback = () => {}) {
if(this.db !== null){
throw new Error(`Database is already open. Close it using "disconnect()".`);
}
if("string" !== typeof name){
throw new TypeError(`Argument provided for database name is not of type "string".`);
}
if("function" !== typeof createdCallback){
throw new TypeError(`Argument provided for the initial creation callback is not a function.`);
}
return new Promise((res, rej) => {
const req = indexedDB.open(name, 1);
req.addEventListener("success", () => {
rej(new Error(`Database is already created.`));
});
req.addEventListener("upgradeneeded", event => {
if(event.oldVersion < 1){
this.db = req.result;
createdCallback(event, this.db);
res(this.db);
}
else{
rej(new Error(`Database is already created.`));
}
});
req.addEventListener("error", err => rej(err));
});
}
createObjectStore(name, options = {}){
if(this.db === null){
throw new Error(`Database is already open. Close it using "disconnect()".`);
}
if("string" !== typeof name){
throw new TypeError(`Argument provided as the object store name is not of type "string".`);
}
if("object" !== typeof options){
throw new TypeError(`Argument provided as the object store options is not of type "object".`);
}
return new Promise(async (res, rej) => {
const dEntries = await indexedDB.databases();
if(dEntries.filter(dEntry => dEntry.name === this.db.name).length < 1){
rej(new Error(`Database is not initialized. Use "create()" instead.`));
return;
}
//TODO & FIXME: Infinite update wait time (I'm probably upgrading it wrong)!!!
const req = indexedDB.open(this.db.name, this.db.version + 1);
req.addEventListener("upgradeneeded", event => {
this.db = req.result;
this.db.createObjectStore(name, options);
console.log(this.db);
});
req.addEventListener("success", () => {
this.db = req.result;
this.db.createObjectStore(name, options);
console.log(req);
res(this.db);
});
console.log(req);
req.addEventListener("error", err => rej(err));
});
}
disconnect() {
this.db = null;
}
};
export default transactions;
Under the "TODO & FIXME", I get an infinite waiting time.
Keeping the same version gives:
transactions.js:141 Uncaught DOMException: Failed to execute ācreateObjectStoreā on āIDBDatabaseā: The database is not running a version change transaction.
at IDBOpenDBRequest. (http://localhost:8888/transactions.js:141:25)
And then doing the current, I have an infinite pending time >:(
node.js?
Uhhhh, no.
IndexedDB is for client.
Pure vanilla JS (which is why I donāt answer questions about redux and such).
I typically hate libraries/frameworks because I want to know how things work, not have people do them for me.
oh i meant is it on browser side or naw?
because i cannot provide solution without trying it ![]()
Yeah.
I think it is blocked (the version upgrade), but I have to see for myself.
I found this but let me try to debug.
Yeah I know.
Oops, my code will give err.
Hang on, let me fix (was trying something and I changed it back now).
There, check the edit.
Ok I found it, I forgot to close the DB XD!
Thatās why i hate programming at this point 
Yeah, XD.
Iām working it out, I think my method might not be possible (thank goodness Iām question banned - MAN I thought Iād never say that)
Iām too lazy to read the code again, is this a library for in-browser database?
Yeah. Got it!
Code:
const { indexedDB } = globalThis;
const awaitEvent = (obj, handlerName, rejOnError = true, timeout = Infinity, callback = () => {}) => {
if("object" !== typeof obj){
throw new TypeError(`Argument provided for object to bind the listener to is not of type "object".`);
}
if("string" !== typeof handlerName){
throw new TypeError(`Argument provided for object's event listener name is not of type "string".`);
}
if("function" !== typeof obj.addEventListener){
throw new TypeError(`Object does not have an "addEventListener" function.`);
}
if("function" !== typeof callback){
throw new TypeError(`Callback provided is not a function.`);
}
/*Status codes:
0: ok
1: timed out
*/
return new Promise((res, rej) => {
obj.addEventListener(handlerName, evt => {
callback(evt);
res({
"ok": true,
"status": 0,
"statusText": ""
});
});
if(timeout !== Infinity && timeout > 0){
globalThis.setTimeout(timeout, () => {
if(rejOnError){
rej({
"ok": false,
"status": 1,
"statusText": ""
});
}
else{
res({
"ok": false,
"status": 1,
"statusText": ""
});
}
});
}
});
};
const transactions = class {
constructor() {
this.db = null;
}
connect(name, version, upgradeNeededCallback = () => {}) {
if(this.db !== null){
throw new Error(`Database is already open. Close it using "disconnect()".`);
}
if("string" !== typeof name){
throw new TypeError(`Argument provided for the database name is not of type "string".`);
}
if("number" !== typeof version){
throw new TypeError(`Argument provided for the version is not of type "number".`);
}
if(version < 1){
throw new TypeError(`Database version cannot be less than one. Expected a greater-than 0 value, got a less-than 0 value of ${version} instead.`);
}
if("function" !== typeof upgradeNeededCallback){
throw new TypeError(`Argument provided for the upgrade needed callback is not a function.`);
}
return new Promise(async (res, rej) => {
const dEntries = await indexedDB.databases();
if(dEntries.filter(dEntry => dEntry.name === name).length < 1){
rej(new Error(`Database is not initialized. Use "create()" instead.`));
return;
}
const req = indexedDB.open(name, version);
req.addEventListener("success", () => {
this.db = req.result;
res(this.db);
});
req.addEventListener("upgradeneeded", event => {
this.db = req.result;
upgradeNeededCallback(event, this.db);
res(this.db);
});
req.addEventListener("error", err => rej(err));
});
}
create(name, createdCallback = () => {}) {
if(this.db !== null){
throw new Error(`Database is already open. Close it using "disconnect()".`);
}
if("string" !== typeof name){
throw new TypeError(`Argument provided for database name is not of type "string".`);
}
if("function" !== typeof createdCallback){
throw new TypeError(`Argument provided for the initial creation callback is not a function.`);
}
return new Promise((res, rej) => {
const req = indexedDB.open(name, 1);
req.addEventListener("success", () => {
rej(new Error(`Database is already created.`));
});
req.addEventListener("upgradeneeded", event => {
if(event.oldVersion < 1){
this.db = req.result;
createdCallback(event, this.db);
res(this.db);
}
else{
rej(new Error(`Database is already created.`));
}
});
req.addEventListener("error", err => rej(err));
});
}
createObjectStore(name, options = {}){
if(this.db === null){
throw new Error(`Database is already open. Close it using "disconnect()".`);
}
if("string" !== typeof name){
throw new TypeError(`Argument provided as the object store name is not of type "string".`);
}
if("object" !== typeof options){
throw new TypeError(`Argument provided as the object store options is not of type "object".`);
}
return new Promise(async (res, rej) => {
this.db.close();
const dEntries = await indexedDB.databases();
if(dEntries.filter(dEntry => dEntry.name === this.db.name).length < 1){
rej(new Error(`Database is not initialized. Use "create()" instead.`));
return;
}
//TODO & FIXME: Infinite update wait time (I'm probably upgrading it wrong)!!!
const req = indexedDB.open(this.db.name, this.db.version + 1);
req.addEventListener("upgradeneeded", event => {
this.db = req.result;
this.db.createObjectStore(name, options);
console.log(this.db);
});
req.addEventListener("success", () => {
this.db = req.result;
this.db.addEventListener("versionchange", () => {
this.db.createObjectStore(name, options);
console.log(req);
res(this.db);
});
});
console.log(req);
req.addEventListener("error", err => rej(err));
req.addEventListener("blocked", err => rej(err));
});
}
disconnect() {
this.db = null;
}
};
export default transactions;
I wish we had executable code blocks like SO does ![]()
Iām making my own transaction handler because itās hard to do indexedDB so Iāll use this for handling DB stuff (Iām using functions for their real purpose: to reduce code redundancies).
I found out the prob from here:
Reading does help! Who knewā¦
OMG I found the best song, but itās not out yet (I have Monstercat gold so I can listen early). Iāll show u when you can view it, itās amazing.
Rich boy >:(
Its legit $60 a year (now $80 but whatever).
Iām actually poor.
Ok, I have $700 saved for a computer, but like itās a dead effort at this point since parents are saying no.
Oh, and btwā¦
Are you celebrating Easter?
We are (kinda).
I⦠legit⦠slept⦠through⦠church!
And not āsleep inā, I actually was asleep.
They were talking about (according to my Mom) how God can bring everything back to life.
Duh, heās God!!!
But I think the more amazing thing is that he chooses to bring things back to life ![]()
As a muslim, not really.
Ahā¦
At least we believe in the same God (with separate qualities, but whatever).
I was going to ask if u were Muslim (since a lot of people in your area probably are, but I donāt want to discriminate or be biased or stereotypical)ā¦
Muslim/Jewish/Christians believe in the same God, practically - more evidence that he exists ![]()