{"id":18576134,"url":"https://github.com/thiagodp/database-js-json","last_synced_at":"2025-04-10T08:31:05.008Z","repository":{"id":150584432,"uuid":"118839709","full_name":"thiagodp/database-js-json","owner":"thiagodp","description":"📜 Query your JSON files with SQL","archived":false,"fork":false,"pushed_at":"2021-01-25T22:01:07.000Z","size":19,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T19:01:42.638Z","etag":null,"topics":["database","database-js","database-js-json","driver","javascript","json","node","query","sql"],"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/thiagodp.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":"2018-01-25T00:26:24.000Z","updated_at":"2024-10-13T09:35:57.000Z","dependencies_parsed_at":"2023-06-11T08:33:48.530Z","dependency_job_id":null,"html_url":"https://github.com/thiagodp/database-js-json","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fdatabase-js-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fdatabase-js-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fdatabase-js-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thiagodp%2Fdatabase-js-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thiagodp","download_url":"https://codeload.github.com/thiagodp/database-js-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248185326,"owners_count":21061498,"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","database-js","database-js-json","driver","javascript","json","node","query","sql"],"created_at":"2024-11-06T23:23:44.127Z","updated_at":"2025-04-10T08:31:04.998Z","avatar_url":"https://github.com/thiagodp.png","language":"JavaScript","readme":"# database-js-json\n\nA [database-js](https://github.com/mlaanderson/database-js) driver for JSON files.\n\n## About\n\nThis is a wrapper around the [jl-sql-api](https://github.com/avz/node-jl-sql-api), intended to be used with [database-js](https://github.com/mlaanderson/database-js) for handling JSON files.\n\nOur [releases](https://github.com/thiagodp/database-js-json/releases) adopt [Semantic Versioning](https://semver.org/).\n\n## Install\n\n```shell\nnpm install database-js-json --save\n```\n\nNote: `database-js` must also be installed.\n\n## Basic Usage\n\n```javascript\nconst Connection = require( 'database-js' ).Connection;\n\n( async () =\u003e {\n    const connection = new Connection( 'json:///test.json' );\n    try {\n        const statement = await connection.prepareStatement(\"SELECT * WHERE user_name = ?\");\n        const rows = await statement.query('not_so_secret_user');\n        console.log(rows);\n    } catch (error) {\n        console.log(error);\n    } finally {\n        await connection.close();\n    }\n} )();\n```\n\n## Example\n\n`people.json`\n```json\n[\n    { \"name\": \"Alice\", \"age\": 21 },\n    { \"name\": \"Bob\", \"age\": 53 },\n    { \"name\": \"Jack\", \"age\": 16 }\n]\n```\n\n`main.js`\n```javascript\nconst dbjs = require( 'database-js' );\n( async () =\u003e {\n    let conn;\n    try {\n        conn = new dbjs.Connection( 'json:///people.json' );\n\n        const st1 = conn.prepareStatement( 'SELECT *' );\n        const r1 = await st1.query();\n        console.log( r1 ); // same as people.json's content\n\n        const st2 = conn.prepareStatement( 'SELECT name ORDER BY name DESC' );\n        const r2 = await st2.query();\n        console.log( r2 ); // [ { name: 'Jack' }, { name: 'Bob' }, { name: 'Alice' } ]\n\n        const st3 = conn.prepareStatement( 'SELECT MAX(age) AS older' );\n        const r3 = await st3.query();\n        console.log( r3 ); // [ { older: 53 } ]\n\n\t\t// Inserting a row\n\t\tconst st4 = conn.prepareStatement( 'INSERT VALUES { \"name\": \"Mary\", \"age\": 18 }' );\n        await st4.execute();\n\n\t\t// Updating a row\n\t\tconst st5 = conn.prepareStatement( 'UPDATE SET name = \"Robert\" WHERE name = \"Bob\"' );\n        await st5.execute();\n\n\t\t// Deleting a row\n\t\tconst st6 = conn.prepareStatement( 'DELETE WHERE name = \"Alice\"' );\n        await st6.execute();\n\n\t\t// Now people.json is\n\t\t// [{\"name\":\"Robert\",\"age\":53},{\"name\":\"Jack\",\"age\":16},{\"name\":\"Mary\",\"age\":18}]\n\n    } catch ( err ) {\n        console.error( err );\n    } finally {\n        if ( conn ) {\n            await conn.close();\n        }\n    }\n} )();\n```\n\n## Basic Options\n\nOptions can be passed as arguments to the database connection string, in URL-format.\n\n- `charset`: defines the charset (encoding) used to handle the JSON file\n  - Defaults to `utf-8`\n  - Example: `const connection = new Connection( 'json:///test.json?charset=utf-16' );`\n  - Available in database-js-json version `1.0.0` or later\n\n- `checkOnConnect`: whether it should check if the file exists when connecting to it\n  - Defaults to `true`\n  - Example: `const connection = new Connection( 'json:///test.json?checkOnConnect=false' );`\n  - Accepts `false`, `no` or `0` as false\n  - Available in database-js-json version `1.1.0` or later\n\n\n## Additional Options\n\nOptions from [jl-sql-api](https://github.com/avz/node-jl-sql-api) can also be passed as arguments to the database connection.\n\nExample: `{ tmpDir: \"/path/to/dir\" }`\n```javascript\nconst connection = new Connection( 'json:///test.json?tmpDir=path/to/dir' );\n```\n\nWhen an option that belongs to a group is informed, it must have a dot.\n\nExample: `{ tmpDir: \"/path/to/dir\", sortOptions: { inMemoryBufferSize: 32000 } }`\n```javascript\nconst connection = new Connection( 'json:///test.json?tmpDir=path/to/dir\u0026sortOptions.inMemoryBufferSize=32000' );\n```\n\n## License\n\n[MIT](https://github.com/thiagodp/database-js-json/blob/master/LICENSE) (c) [Thiago Delgado Pinto](https://github.com/thiagodp)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fdatabase-js-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagodp%2Fdatabase-js-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagodp%2Fdatabase-js-json/lists"}