{"_id":"@allnulled/webmarket","name":"@allnulled/webmarket","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@allnulled/webmarket","version":"1.0.0","description":"Wrapper for IndexedDB.","main":"webmarket.js","scripts":{"serve":"npx http-server -c-1 . -o"},"keywords":["indexeddb","wrapper","idb","database","browser","db"],"author":{"name":"allnulled"},"license":"WTFPL","gitHead":"8e96ce4a729d945809cdffc7acc9a1bb40a74481","_id":"@allnulled/webmarket@1.0.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-c2+8bfqHt8npnytRooTCdn/RzrVdiGGC2jkYxnNCNaqWV4uokrnAgjbitzOcUnUaacFnGMLpq9AVjiIoEvvmXQ==","shasum":"8cab4f2b76d0104f5417475c94ffcd221964b7eb","tarball":"https://registry.npmjs.org/@allnulled/webmarket/-/webmarket-1.0.0.tgz","fileCount":4,"unpackedSize":13791,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCHCUETRr++dMkiQqQRSl/YtZN1WWL08R+4fXtRH69rlAIhAMrZhzBlECRPnmpfUTLJqPiTKjG4hnpmsB0N01+lYdRQ"}]},"_npmUser":{"name":"allnulled","email":"todosanulados@gmail.com"},"directories":{},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/webmarket_1.0.0_1734713603568_0.514213678263455"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-20T16:53:23.484Z","1.0.0":"2024-12-20T16:53:23.735Z","modified":"2024-12-20T16:53:24.040Z"},"maintainers":[{"name":"allnulled","email":"todosanulados@gmail.com"}],"description":"Wrapper for IndexedDB.","keywords":["indexeddb","wrapper","idb","database","browser","db"],"author":{"name":"allnulled"},"license":"WTFPL","readme":"# webmarket\n\nWrapper for IndexedDB.\n\n## Installation\n\n```sh\nnpm install --save @allnulled/webmarket\n```\n\nThen:\n\n```html\n<script src=\"node_modules/@allnulled/webmarket/webmarket.js\"></script>\n```\n\n## Usage\n\n```js\nconst wm = await Webmarket.open();\n// @TODO: operations\n```\n\n## Operations\n\nThe `window.Wemarket` global class has some methods:\n\n - `static create(dbName)`: creates an instance.\n    - Receives `String:dbName`, the name of the database.\n    - Returns `Webmarket` type.\n - `static open(dbName)`: creates and initializes an instance.\n    - Receives `String:dbName`, the name of the database.\n    - Returns `Promise<Webmarket>` type.\n - `static init(dbName)`\n    - Receives `String:dbName`, the name of the database.\n    - Return `Promise<Webmarket>` type, and returns `wm.init()`.\n - `static listDatabases()`\n    - Receives nothing.\n    - Returns the list of names of databases found.\n - `constructor(dbName = \"webmarket\")`\n    - Receives `String:dbName`, the name of the database.\n    - Creates the object only. You still need to call to `wm.init()`.\n - `async init()`\n    - Receives nothing. Uses the `this.dbName` set on the constructor.\n    - Ensures the current store and returns an internal IDB object.\n - `async changeDatabase(dbName)`\n    - Receives `String:dbName`, the name of the database.\n    - Changes the name of the database, and calls `wm.init()` again.\n - `async select()`\n    - Receives nothing. Filters are complicated in IDB.\n    - Returns a list of all the items.\n - `async selectById(id)`\n    - Receives `Integer:id`, the `id` of the row to select.\n    - Returns the item by id, if found.\n - `async insertOne(data)`\n    - Receives `Object:item`, the `item` to insert.\n    - Inserts one item.\n    - Returns the inserted `id`.\n - `async insertMany(items)`\n    - Receives `Array<Object>:items`, the `items` to insert.\n    - Inserts a list of items.\n    - Returns the inserted `id`s in a list.\n - `async updateOne(id, data)`\n    - Receives `Integer:id`, the `id` of the row to update.\n    - Updates one item.\n    - Returns the updated `id`.\n - `async deleteOne(id)`\n    - Receives `Integer:id`, the `id` of the row to delete.\n    - Deletes one item.\n    - Returns nothing.\n\n## How it better works?\n\nJust remember this.\n\nDatabases are directories. Rows are files indexed by `id`.\n\nThere are no stores with webmarket, no schema versions, no schema modifications.\n\nOnly 1 directory and N files. Only 1 database and N registries.\n\n### Steps\n\n1. You `open` database and store. `wm = Webmarket.open(dbName)`\n2. You operate the CRUD like so:\n   1. `all = await wm.select()`\n   1. `one = await wm.selectById(1)`\n   1. `id = await wm.insertOne({})`\n   1. `ids = await wm.insertMany([{}, {}, {}])`\n   1. `id = await wm.updateOne(1, {})`\n   1. `await wm.deleteOne(1)`\n\nBy default, you work on `\"webmarket\"` database, and `webstore` store.\n\nThe idea is to only alter the `database` name.\n\n## Test\n\n```js\n// Creamos una instancia de Webmarket\nconst wm = await Webmarket.open(\"testDB\");\n\n// Insertamos un solo dato\nconst id = await wm.insertOne({ name: \"Item 1\", description: \"First item\" });\nconsole.log(`Inserted item with ID: ${id}`);\n\n// Insertamos varios datos\nconst ids = await wm.insertMany([\n    { name: \"Item 2\", description: \"Second item\" },\n    { name: \"Item 3\", description: \"Third item\" }\n]);\nconsole.log(`Inserted items with IDs: ${ids.join(\", \")}`);\n\n// Recuperamos todos los elementos\nconst items = await wm.select();\nconsole.log(\"All items:\", items);\n\n// Actualizamos un elemento\nawait wm.updateOne(id, { name: \"Updated Item 1\", description: \"Updated description\" });\nconsole.log(\"Updated item with ID:\", id);\n\n// Recuperamos el elemento actualizado\nconst updatedItem = await wm.selectById(id);\nconsole.log(\"Updated item:\", updatedItem);\n\n// Eliminamos un elemento\nawait wm.deleteOne(id);\nconsole.log(\"Deleted item with ID:\", id);\n\n// Recuperamos todos los elementos después de la eliminación\nconst remainingItems = await wm.select();\nconsole.log(\"Remaining items:\", remainingItems);\n```","readmeFilename":"README.md"}