Use Python ReplDB Dict Syntax in JS

I implemented repldb indexer syntax in javascript using the Proxy class.
You can even go beyond that and just access them like properties :slight_smile:
Just keep in mind the accesses are still async.

let db = require("./database.js")();

(async () => {
	console.log(await db.test); // null on first run
	
	db["easy"] = { value: 15 };

	await db.$set("guaranteed_order", 1704); // Access to normal set function
    // Otherwise you can't guarantee keys will be set if you use them right after.

	console.log(await db.guaranteed_order); // Always 1704

	console.log(await db["easy"]);

	db.test = 80;
})();
2 Likes

Very nice! If you add caching, you might be able to circumvent the need for the user to handle promises at all.

Completely forgot to add the link https://replit.com/@CSharpIsGud/ReplDB-Python-Usage-for-JS?v=1

1 Like