{"id":19227779,"url":"https://github.com/obaydmerz/nodeorm","last_synced_at":"2025-04-21T01:31:42.853Z","repository":{"id":185667891,"uuid":"670233885","full_name":"obaydmerz/nodeorm","owner":"obaydmerz","description":"A laravel-like database management library for nodejs","archived":false,"fork":false,"pushed_at":"2024-08-22T15:07:10.000Z","size":1093,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-17T14:38:37.514Z","etag":null,"topics":["automation","data","database","dependency-less","easy","heidisql","laravel","library","manage","management","mysql","node","nodejs","orm","sql","sqlite","useful"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/obaydmerz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-24T15:28:06.000Z","updated_at":"2024-08-22T15:07:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"583b4886-7a10-4b69-a696-0edca0ce5a25","html_url":"https://github.com/obaydmerz/nodeorm","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"2f7bd8e91a7d0b4f18af59d8214bae673d9884ca"},"previous_names":["obaydmerz/nodeorm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obaydmerz%2Fnodeorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obaydmerz%2Fnodeorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obaydmerz%2Fnodeorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obaydmerz%2Fnodeorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obaydmerz","download_url":"https://codeload.github.com/obaydmerz/nodeorm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249982522,"owners_count":21355707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","data","database","dependency-less","easy","heidisql","laravel","library","manage","management","mysql","node","nodejs","orm","sql","sqlite","useful"],"created_at":"2024-11-09T15:25:04.748Z","updated_at":"2025-04-21T01:31:41.804Z","avatar_url":"https://github.com/obaydmerz.png","language":"JavaScript","readme":"![NodeORM cover](https://raw.githubusercontent.com/obaydmerz/nodeorm/master/docs/cover.png)\n# NodeORM - A laravel-like database management library for nodejs\n\nNodeORM is a lightweight and flexible Object-Relational Mapping (ORM) library for Node.js applications inspired by `Laravel`'s one. It provides a seamless interface between JavaScript objects and relational databases, making it easier for developers to interact with their databases using familiar JavaScript syntax.\n\nIt simplifies and streamlines the process of working with relational databases, making database interactions more intuitive and developer-friendly. It empowers developers to focus on building robust applications without worrying about the complexities of database management. Whether you are working with MySQL, SQLite, or custom database solutions, NodeORM offers a seamless and consistent interface for your database needs.\n\n## Installation\n\nIt's heavily recommended to install from github to get latest changes.\n\n```bash\nnpm install obaydmerz/nodeorm\n```\n\nHowever, for most stable builds you could use npm.\n\n```bash\nnpm install @obayd/nodeorm\n```\n\n## Keyfeatures\n\n- **Database Agnostic:** NodeORM supports multiple database drivers, including MySQL, SQLite, and custom raw function drivers, allowing users to work with their preferred databases.\n\n- **Model Definition:** Users can define their database models with properties such as table name, columns, and primary keys. This enables easy mapping of database tables to JavaScript classes.\n\n- **Fluent Query Building:** With a fluent method chaining syntax, NodeORM allows users to construct complex SQL queries in a natural and intuitive way, making it easy to create dynamic queries for database operations.\n\n- **ModelItem Class:** The ModelItem class represents individual items (rows) in the database table with CRUD methods. Users can interact with specific database records using this class.\n\n- **Collection Class:** The Collection class represents a group of ModelItems with grouping and filtering capabilities. It enables users to work with multiple records as a cohesive unit.\n\n- **Error Handling:** NodeORM defines custom error classes for specific error scenarios, such as EmptyDataError and UnmatchingStateError. This helps users handle errors more effectively and gracefully.\n\n- **Dynamic Model Creation:** Users can dynamically create models during runtime, eliminating the need to predefine them. This flexibility allows for more dynamic and adaptive database interactions.\n\n- **Lazy Loading:** NodeORM employs lazy loading optimizations during iteration, improving performance when dealing with large datasets.\n\n- **Dependency-less:** A plug and play library.\n\n- **Fully compatible:** The library automatically plugs with `mysql`, `mysql2` and-or `sqlite3`.\n\n- **Multi connections:** You can connect to multiple databases at the same time seamlessly.\n\n- **Unblocking structure:** This library is based on async-await syntax.\n\n- _And much other stuff..._\n\n## Driver Usage\nNodeORM will choose the best library to connect to MySQL server.\nConsider this little example.\n\n### MySQL Usage\n\n| Condition                                         | Library Used                   |\n|---------------------------------------------------|--------------------------------|\n| Both `mysql2` and `mysql` are present             | `mysql2`                       |\n| Only `mysql2` is present                          | `mysql2`                       |\n| Only `mysql` is present                           | `mysql`                        |\n| `MySQLDBDriver.library = \"mysql2\"`                | `mysql2`                       |\n| `MySQLDBDriver.library = \"mysql\"`                 | `mysql`                        |\n| `MySQLDBDriver.library = \"xxx\"`                   | `xxx`                          |\n| Using env and `DB_LIBRARY` is unset               | MySQLDBDriver.library `mysql2` |\n| Using env and `DB_LIBRARY` is set to `mysql2`     | `mysql2`                       |\n| Using env and `DB_LIBRARY` is set to `mysql`      | `mysql`                        |\n| Using env and `DB_LIBRARY` is set to `xxx`        | `xxx`                          |\n\n\n### SQLite Usage\n\n| Condition                                           | Library Used                     |\n|-----------------------------------------------------|----------------------------------|\n| `sqlite3` is present                                | `sqlite3`                        |\n| `SQLiteDBDriver.library = \"sqlite3\"`                | `sqlite3`                        |\n| `SQLiteDBDriver.library = \"xxx\"`                    | `xxx`                            |\n| Using env and `DB_LIBRARY` is unset                 | SQLiteDBDriver.library `sqlite3` |\n| Using env and `DB_LIBRARY` is set to `sqlite3`      | `sqlite3`                        |\n| Using env and `DB_LIBRARY` is set to `xxx`          | `xxx`                            |\n\n## Examples\n\nLet's assume that we have the following MySQL structure.\n\n![image](https://github.com/obaydmerz/nodeorm/assets/45913764/4b379c0a-e2ed-43f2-aef1-6b145c49f200)\n\n```javascript\n// MySQL example\n// Inserting a new row/item into a table named `test`.\n\nimport { Model, initialize } from \"@obayd/nodeorm\";\n\nclass Test extends Model {}\n\n(async () =\u003e {\n  await initialize(\"mysql://root@localhost:3306/mydb\", Test);\n\n  const myNewItem = Test.create();\n\n  myNewItem.string_value = \"We have a better tomorrow!\";\n  myNewItem.integer_value = 2024;\n\n  await myNewItem.save();\n\n  console.log(myNewItem.id); // Output: 1\n})();\n```\n\n_Changes in database:_\n\n![image](https://github.com/obaydmerz/nodeorm/assets/45913764/739154df-3e13-49c4-b9f1-361dce2bf661)\n\n\n```javascript\n// Reading the row that we just inserted.\n// We used here an attribute *getter*\n\nimport { Model, initialize } from \"../index.js\";\n\nclass Test extends Model {\n  static _ourPhrase() {\n    // We used here an attribute *getter*\n    // Note we used the following syntax _attributeName\n    return this.string_value + \" in the year of \" + this.integer_value;\n  }\n}\n\n(async () =\u003e {\n  await initialize(\"mysql://root@localhost:3306/mydb\", Test);\n\n  const myLastItem = await Test.last();\n\n  // We accessed an additional attribute.\n  console.log(myLastItem.ourPhrase); // Output: We have a better tomorrow! in the year of 2024\n})();\n\n```\n\n```javascript\n// Editing the row that we just inserted.\n\nimport { Model, initialize } from \"@obayd/nodeorm\";\n\nclass Test extends Model {}\n\n(async () =\u003e {\n  await initialize(\"mysql://root@localhost:3306/mydb\", Test);\n\n  const myLastItem = await Test.last();\n\n  myLastItem.integer_value = 2025;\n\n  await myLastItem.save();\n})();\n```\n\n_Changes in database:_\n\n![image](https://github.com/obaydmerz/nodeorm/assets/45913764/1f14105d-c9cc-47df-96a7-c9bfe4564037)\n\n```javascript\n// Deleting the row that we just inserted.\n// Demonstrates how to use find() to *find* items\n\nimport { Model, initialize } from \"@obayd/nodeorm\";\n\nclass Test extends Model {}\n\n(async () =\u003e {\n  await initialize(\"mysql://root@localhost:3306/mydb\", Test);\n\n  //const myLastItem = await Test.last();\n\n  // We used find() syntax instead of last() just to demonstrate how it works.\n  //const myLastItem = await Test.where(\"id\", 1);\n  //const myLastItem = await Test.where(\"id\", \"=\", 1);\n  const myLastItem = await Test.find(1);\n\n  await myLastItem.delete();\n})();\n\n```\n\n_Changes in database:_\n\n![image](https://github.com/obaydmerz/nodeorm/assets/45913764/fda459f3-d8a9-4db8-b6f9-8a5ff3476631)\n\n##### [HeidiSQL](https://github.com/HeidiSQL/HeidiSQL) is used to show database changes, consider supporting it.\n\n\n#### Multi-support\nNodeORM features accessing and managing other types of databases like sqlite.\n\n\n```javascript\n// SQLite example\nimport { Model, initialize } from \"@obayd/nodeorm\";\n\nclass Test extends Model {}\n\n(async () =\u003e {\n  await initialize(\"C:/Users/Hello/Documents/mysqlite.db\", Test);\n\n  const my = await Test.last();\n  console.log(my.string_value);\n})();\n```\n\n**_Easy, isn't it?_**\n\n### Read more\n\nFor more information and advanced usage, check out the [NodeORM Wiki](https://github.com/obaydmerz/nodeorm/wiki)\n\nYou can join our [discord server](https://discord.gg/2xZEbG4Mb2).\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobaydmerz%2Fnodeorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobaydmerz%2Fnodeorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobaydmerz%2Fnodeorm/lists"}