{"id":15728629,"url":"https://github.com/medsaad/oraios-queries","last_synced_at":"2026-05-08T14:42:34.928Z","repository":{"id":57315973,"uuid":"254846542","full_name":"Medsaad/oraios-queries","owner":"Medsaad","description":"A light-weighted project aims to provide class-based table representation and flexible query experience to help developers to avoid plain string queries that are error-prune once the query start to gets a little long.","archived":false,"fork":false,"pushed_at":"2020-05-20T14:22:51.000Z","size":420,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-07T08:09:28.847Z","etag":null,"topics":["database","model","mysql2","orm","postgres","query-builder"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Medsaad.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}},"created_at":"2020-04-11T10:46:52.000Z","updated_at":"2020-05-20T14:22:54.000Z","dependencies_parsed_at":"2022-08-25T20:40:40.693Z","dependency_job_id":null,"html_url":"https://github.com/Medsaad/oraios-queries","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/Medsaad/oraios-queries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Medsaad%2Foraios-queries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Medsaad%2Foraios-queries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Medsaad%2Foraios-queries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Medsaad%2Foraios-queries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Medsaad","download_url":"https://codeload.github.com/Medsaad/oraios-queries/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Medsaad%2Foraios-queries/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264040938,"owners_count":23548070,"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":["database","model","mysql2","orm","postgres","query-builder"],"created_at":"2024-10-03T23:05:05.103Z","updated_at":"2026-05-08T14:42:34.895Z","avatar_url":"https://github.com/Medsaad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Oraios Queries\n![npm](https://img.shields.io/npm/v/oraios-queries)\n![npm](https://img.shields.io/npm/dw/oraios-queries)\n![NPM](https://img.shields.io/npm/l/oraios-queries)\n\nOraios Queries (formerly [node-db-models](https://www.npmjs.com/package/node-db-models)) is a light-weighted project aims to provide class-based table representation and flexible query experience to help developers to avoid plain string queries that are error-prune.\n\n### [Visit Documentation](https://medsaad.github.io/oraios-queries/index.html)\n\n- [Features](#features)\n- [Get Started](#get-started)\n- [Code Examples](#code-examples)\n\nOraios Queries supports [postgres](https://www.npmjs.com/package/pg) and [mysql2](https://www.npmjs.com/package/mysql2) packages.\n\n## Features\nThe package is consistently getting enhanced and updated. Your contributions are always welcome. Here are the functionality that are developed/being developed:\n- **CRUD Ops**: Insert, select, update \u0026 delete Data from Postgresql and MySQL with flexible nested WHERE conditions.\n- **ORM**: Create class-based models for your tables with built-in features.\n- **Flexible Queries**: Designed to perform flexible, nested WHERE statements, ordering and grouping.\n- **Model Settings**: Specify certain fields to be selectable, allow HTML tags to be stored in database for certain fields, add default values on insert and update, and more.\n- **Pre-defined Query Executers**: Extract data in various ways: list, select one column, first item, slicing, chunking, pagination and more.\n- **Light Weighted**: This package is light and can be added on APIs, web workers, .. etc.\n\n## Get Started\nInstall package using npm:\n```\n$ npm install --save oraios-queries\n```\n\nConnect to your database using [pg](https://www.npmjs.com/package/pg) or [mysql2](https://www.npmjs.com/package/mysql2) package, then attach your connection with oraios-queries:\n### For Postgres:\n\n```javascript\nconst Pg = require(\"pg\");\nconst { Connection, Model } = require('oraios-queries');\n\nlet pgModConn = new Pg.Pool({\n        host: '127.0.0.1',\n        user: 'admin',\n        database: 'sampledb',\n        password: '*******',\n        port: 5432\n});\n\nlet conn = new Connection({\n        connection: pgModConn,\n        type: 'pg'\n});\n```\n\n### For MySQL:\n```javascript\n\nconst mysql = require('mysql2');\nconst { Connection, Model } = require('oraios-queries');\n\nconst mysqlConn = mysql.createPool({\n        host: '127.0.0.1',\n        user: 'admin',\n        password: '*****',\n        database: 'sampledb',\n        waitForConnections: true,\n        connectionLimit: 10,\n        queueLimit: 0\n});\n\nlet conn = new Connection({\n        connection: mysqlConn,\n        type: 'mysql'\n});\n```\nThat's it. From now on everything will be the same across different connections.n rows in database.\n\n### [Visit Documentation](https://medsaad.github.io/oraios-queries/doc.html)\n\n## Code Examples\n- Create a Model:\n```javascript\nconst { Model, Util } = require('oraios-queries');\n\nclass Post extends Model {\n        tableName = 'posts';\n        allowHtml = ['body'];\n        selectable = ['title', 'body', 'author_id', 'created_at::date'];\n        \n        //optional, default value is 'id'\n        primaryKey = 'uuid';\n\n        //the object created above\n        connection = conn;\n        \n        //optional default value setup\n        defaultValue = {\n                onInsert: {\n                        created_at: Util.timestamp(),\n                        updated_at: Util.timestamp()\n                },\n                onUpdate: {\n                        updated_at: Util.timestamp()\n                }\n        }\n}\n```\n- Inserting new row to database:\n```javascript\nlet insertedId = await post.set({title: 'blog post', body: '\u003cp\u003eHello World\u003c/p\u003e'}).insert();\nif(insertedId){\n        //success\n}\n```\n- Inserting multiple rows to database:\n```javascript\nlet insertedRows = await post.setMany([\n        {title: 'blog post', body: '\u003cp\u003eHello World\u003c/p\u003e'},\n        {title: 'blog post 2', body: '\u003cp\u003eHello Oraios\u003c/p\u003e'}\n        ]).insert();\nif(insertedRows \u003e 0){\n        //success\n}\n```\n- Updating certain rows in database:\n```javascript\nlet affectedRows = await post.set({title: 'another blog post'}).where(['id', '=', 25]).update();\nif(affectedRows !== 0){\n        //update successful\n}\n```\n- Deleting a row in database:\n```javascript\nlet rowDeleted = await post.where(['id', '=', 25]).delete();\nif(rowDeleted !== 0){\n        //delete successful\n}\n```\n- Find a row by id in database:\n```javascript\nlet row = await post.find(25);\n```\n- Perform a query with joins:\n```javascript\nlet userJoinQuery = user.innerJoin(post, 'id', 'post_author').select(['user_email']);\nlet userEmails = await userJoinQuery.list();\n```\n- Select query with conditions using AND \u0026 OR with grouping:\n```javascript\nlet post = new Post();\nlet conditions = nestedConditions = { cond: [] };\n\nconditions.relation = 'AND';\nconditions.cond.push([\"created_at::date\", \"\u003e\", \"2019-01-01\" ]);\nconditions.cond.push([\"author_id\", \"=\", 25 ]);\n\n//include a nested condition\nnestedConditions.relation = 'OR';\nnestedConditions.cond.push(['created_at::date', \"\u003e\", \"2019-05-01\"]);\nnestedConditions.cond.push(['created_at::date', \"\u003c\", \"2019-10-01\"]);\n\n//add nested condition into the list of conditions\nconditions.cond.push(nestedConditions);\nlet postQuery = post.select(['created_at::date', 'count(*) as posts'])\n        .where(conditions)\n        .groupBy(['created_at::date'])\n        .orderBy([{col: 'created_at::date', order: 'desc'}]);\n        \nlet postRes = await postQuery.list();\n```\nThe previous statement will produce a query like this:\n```sql\nSELECT created_at::date, count(*) as posts \nFROM posts \nWHERE (\n        created_at::date \u003e \"2019-01-01\" AND \n        author_id, \"=\", 25 AND\n        (\n                created_at::date \u003e \"2019-05-01\" OR\n                created_at::date \u003c \"2019-10-01\"\n        )\n) \nGROUP BY created_at::date \nORDER BY created_at::date desc;\n```\n\nCopyright (c) 2019-2020 Ahmed Saad Zaghloul (ahmedthegicoder@gmail.com) MIT License","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedsaad%2Foraios-queries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmedsaad%2Foraios-queries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedsaad%2Foraios-queries/lists"}