{"id":19990366,"url":"https://github.com/planetarydev/json-sql-builder","last_synced_at":"2025-05-04T09:35:24.355Z","repository":{"id":57285279,"uuid":"100971805","full_name":"planetarydev/json-sql-builder","owner":"planetarydev","description":"SQLBuilder to translate json dataformat like mongo to SQL","archived":true,"fork":false,"pushed_at":"2019-07-30T04:56:07.000Z","size":401,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-31T17:45:19.659Z","etag":null,"topics":["json","json-sql-builder","mongo","mysql","postgresql","sql","translate"],"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/planetarydev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-21T16:25:56.000Z","updated_at":"2024-02-01T02:42:46.000Z","dependencies_parsed_at":"2022-08-31T14:23:37.546Z","dependency_job_id":null,"html_url":"https://github.com/planetarydev/json-sql-builder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fjson-sql-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fjson-sql-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fjson-sql-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fjson-sql-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/planetarydev","download_url":"https://codeload.github.com/planetarydev/json-sql-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224391390,"owners_count":17303609,"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":["json","json-sql-builder","mongo","mysql","postgresql","sql","translate"],"created_at":"2024-11-13T04:51:11.157Z","updated_at":"2024-11-13T04:51:35.208Z","avatar_url":"https://github.com/planetarydev.png","language":"JavaScript","readme":"# json-sql-builder\n\nWriting your SQL-Queries in a way like mongo. Use JSON to define all the queries you like to run.\n\nBy default `json-sql-builder` supports the ANSI-SQL language. In addition to this you can specify a dialect like `mysql` or `postgreSQL`.\nAt this time we will support additional language helpers and operators for:\n- [x] ANSI\n- [x] MySQL\n- [x] PostgreSQL\n- [ ] Oracle\n- [ ] Microsoft SQL Server\n\n\n## Current Dev Stage\n\nThis repo was no longer maintained, because of a new Version of json-sql-builder. Have a look at [json-sql-builder2](https://github.com/planetarydev/json-sql-builder2)\n\n## Install\n\n```sh\nnpm install json-sql-builder --save\n```\n\n## Getting Started\n\n```javascript\nconst SQLBuilder = require('json-sql-builder');\n// create a new instance of the SQLBuilder and load the language extension for mysql\nvar sqlbuilder   = new SQLBuilder('mysql');\n\n// lets start some query fun\nvar totalSalary = sqlbuilder.build({\n\t$select: {\n\t\t$columns: [\n\t\t\t'job_title',\n\t\t\t{ total_salary: { $sum: 'salary' } }\n\t\t],\n\t\t$from: 'people',\n\t\t$where: {\n\t\t\tjob_title: { $in: ['Sales Manager', 'Account Manager'] },\n\t\t\tage: { $gte: 18 },\n\t\t\tcountry_code: 'US',\n\t\t},\n\t\t$groupBy: ['job_title'],\n\t}\n});\n\n```\n\n**Result**\n```javascript\n// totalSalary.sql\nSELECT\n\t`job_title`,\n\tSUM(`salary`) AS `total_salary`\nFROM\n\t`people`\nWHERE\n\t`job_title` IN (?, ?)\nAND `age` \u003e= ?\nAND `country_code` = ?\nGROUP BY\n\t`job_title`\n\n// totalSalary.values\n['Sales Manager', 'Account Manager', 18, 'US']\n\n\n// general output\nqueryOutput = {\n\tsql: 'Your SQL-query-string'\n\tvalues: ['Array', 'with', 'all', 'Query-values']\n\ttimeout: 10000 // depends on the options\n}\n\n```\n\n\n\n# Release notes\n\n### 1.0.19 Bugfixing\n- Join Support for MySQL and PostgreSQL should work now\n- Fix Support for Sub-Select's with AS clause\n\n\n### 1.0.17+18 Bugfixing, Update docs\n- Parameterized queries for PostgreSQL using $create operator. The params will now safely escaped by pg-format because PostgreSQL does not support parameters on CREATE statements.\n\n\n### 1.0.16 Add `CREATE VIEW` Support with new operators and helpers\n- ANSI using `$create: { $view: 'myView', $select: {...} }`\n\n```javascript\nvar query = sqlbuilder.build({\n\t$create: {\n\t\t$view: { $cor: 'v_people' },\n\t\t$select : {\n\t\t\t$from: 'people',\n\t\t\t$columns: [\n\t\t\t\t'first_name',\n\t\t\t\t'last_name'\n\t\t\t]\n\t\t}\n\t}\n});\n\n// OUTPUT\nCREATE OR REPLACE VIEW `v_people` AS\n\tSELECT\n\t\t`first_name`,\n\t\t`last_name`\n\tFROM\n\t\t`people`;\n```\n\n### 1.0.15 Add Support for ANSI `JOIN` operators\n- INNER JOIN\n- LEFT JOIN\n- RIGHT JOIN\n- FULL OUTER JOIN\n\n```javascript\nvar query = sqlbuilder.build({\n\t$select: {\n\t\t$from: 'public.users',\n\t\t$joins: {\n\t\t\t'public.users_profiles': { $as: 'profile', $innerJoin: { 'public.users.id': { $eq: { $column: 'profile.user_id' } } } },\n\t\t\t'public.users_likes': { $as: 'likes',\n\t\t\t\t$leftJoin: {\n\t\t\t\t\t$and: [\n\t\t\t\t\t\t{ 'likes.user_id': { $eq: { $column: 'public.users.id' } } },\n\t\t\t\t\t\t{ 'likes.score': { $gt: 1 } }\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n});\n```\n\n### 1.0.15 Add PostgreSQL JSON helpers\n- $rowToJson\n- $jsonBuildObject\n\n```javascript\n// Example using $jsonBuildObject\nvar query = sqlbuilder.build({\n\t$select: { $columns: [\n\t\t{ peopleData: { $jsonBuildObject: { firstName: 'John', lastName: 'Doe' } } }\n\t] }\n});\n\nSELECT\n\tjson_build_object('firstName', $1, 'lastName', $2) AS \"peopleData\"\nFROM\n\t\"people\"\n\n\n// Example using $rowToJson\nvar query = sqlbuilder.build({\n\t$select: {\n\t\t$from: 'people',\n\t\t$columns: [\n\t\t\t{ peopleData: { $rowToJson: 'people' } }\n\t\t]\n\t}\n});\n\nSELECT\n\trow_to_json(\"people\") AS \"peopleData\"\nFROM\n\t\"people\";\n```\n\n\n### 1.0.14 Add `CREATE INDEX` operators and helpers for\n- ANSI using `$create: { $index: 'myidx', $table: 'mytable', $columns: {...} }`\n- Move `$ine` to Basic Helpers and support Boolean and String expressions\n- Update tests and docs\n\n```javascript\nvar query = sqlbuilder.build({\n\t$create: {\n\t\t$index: 'idx_people_last_name',\n\t\t$table: 'people',\n\t\t$columns: {\n\t\t\tlast_name: { $asc: true },\n\t\t\tfirst_name: { $asc: true },\n\t\t},\n\t\t$using: 'BTREE'\n\t}\n}\n\n// OUTPUT\nCREATE INDEX `idx_people_last_name` ON `people` USING BTREE (\n\t`last_name` ASC,\n\t`first_name` ASC\n);\n```\n\n### 1.0.13 Add `CREATE TABLE` operators and helpers for\n- ANSI\n- PostgreSQL\n- MySQL\n- Update tests and docs\n\n```javascript\nvar query = sqlbuilder.build({\n\t$create: {\n\t\t$table: 'users',\n\t\t$define: {\n\t\t\t_id: { $column: { $type: 'VARCHAR', $length: 32, $notNull: true } },\n\t\t\tusername: { $column: { $type: 'TEXT' } },\n\t\t\tfirst_name: { $column: { $type: 'TEXT' } },\n\t\t\tlast_name: { $column: { $type: 'TEXT', $default: 'John' } },\n\t\t\tcreatedAt: { $column: { $type: 'DATETIME', $notNull: true } },\n\n\t\t\tpk_users: { $constraint: { $primary: true, $columns: '_id' } },\n\t\t\tuc_users_username: { $constraint: { $unique: true, $columns: 'username' } }\n\t\t}\n\t}\n});\n\n// OUTPUT\nCREATE TABLE `users` (\n\t`_id` VARCHAR (32) NOT NULL,\n\t`username` TEXT,\n\t`first_name` TEXT,\n\t`last_name` TEXT DEFAULT ?,\n\t`createdAt` DATETIME NOT NULL,\n\n\tCONSTRAINT `pk_users` PRIMARY KEY (`_id`),\n\tCONSTRAINT `uc_users_username` UNIQUE (`username`)\n);\n```\n\n### 1.0.12 Add helpers and operators for **postgreSQL**\n- `LIMIT` and `LIMIT ALL` using `$limit`\n- `OFFSET` using `$offset`\n- add `sqlDialect` property to sqlBuilder to use it inside of helper-functions\n\n### 1.0.11 Add helpers and operators for **postgreSQL**\n- `ON CONFLICT` clause using `$confict`\n- Update documetation\n\n### 1.0.10 Add helpers and operators for **postgreSQL**\n- Function `json_agg()` using `$jsonAgg`\n- Function `to_json()` using `$json`\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanetarydev%2Fjson-sql-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplanetarydev%2Fjson-sql-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanetarydev%2Fjson-sql-builder/lists"}