{"id":29075172,"url":"https://github.com/quackscience/duckdb-quickjs","last_synced_at":"2025-06-27T15:10:22.076Z","repository":{"id":300778685,"uuid":"1007088797","full_name":"quackscience/duckdb-quickjs","owner":"quackscience","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-23T15:13:44.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-23T15:34:46.722Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/quackscience.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,"zenodo":null}},"created_at":"2025-06-23T12:53:23.000Z","updated_at":"2025-06-23T15:13:47.000Z","dependencies_parsed_at":"2025-06-23T15:48:44.336Z","dependency_job_id":null,"html_url":"https://github.com/quackscience/duckdb-quickjs","commit_stats":null,"previous_names":["quackscience/duckdb-quickjs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/quackscience/duckdb-quickjs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-quickjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-quickjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-quickjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-quickjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quackscience","download_url":"https://codeload.github.com/quackscience/duckdb-quickjs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-quickjs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262279297,"owners_count":23286554,"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":[],"created_at":"2025-06-27T15:10:21.482Z","updated_at":"2025-06-27T15:10:22.067Z","avatar_url":"https://github.com/quackscience.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/user-attachments/assets/46a5c546-7e9b-42c7-87f4-bc8defe674e0\" width=250 /\u003e\n\n# DuckDB QuickJS Extension\n\nThis extension provides an embedded [QuickJS-NG](https://github.com/quickjs-ng/quickjs) engine for [DuckDB](https://duckdb.org/). It allows you to execute JavaScript code directly within your SQL queries. QuickJS is a small, fast, and embeddable JavaScript engine that supports modern JavaScript features including ES2020.\n\n## Functions\n\n### Scalar `quickjs(code)`\nExecutes JavaScript code and returns the result as a string.\n\n```sql\nSELECT quickjs('2 + 2');\n-- Returns: 4\n\nSELECT quickjs('let msg = \"Hello, World!\"; msg');\n-- Returns: Hello, World!\n```\n\n**Note:** For string literals with nested quotes, assign them to variables first to avoid parser confusion.\n\n### Scalar `quickjs_eval(function, ...args)`\nExecutes a JavaScript function with the provided arguments and returns the result as JSON.\n\n```sql\nSELECT quickjs_eval('(a, b) =\u003e a + b', 5, 3);\n-- Returns: 8\n```\n\n### Table `quickjs(code, ...args)`\nExecutes JavaScript code that returns an array and returns each array element as a separate row in a table. Accepts optional parameters that can be passed to the JavaScript function.\n\n```sql\n-- Simple array\nSELECT * FROM quickjs('[1, 2, 3, 4, 5]');\n-- Returns:\n-- 1\n-- 2\n-- 3\n-- 4\n-- 5\n\n-- With parameters\nSELECT * FROM quickjs('parsed_arg0.map(x =\u003e x * arg1)', '[1, 2, 3, 4, 5]', 3);\n-- Returns:\n-- 3\n-- 6\n-- 9\n-- 12\n-- 15\n```\n\n**Parameter Naming Convention:**\n- `arg0`, `arg1`, `arg2`, etc. - Access to the raw parameters passed to the function\n- `parsed_arg0` - The first parameter parsed as JSON (if it's a string). This is useful when passing arrays or objects as the first parameter.\n\n## Features\n\n- **Full JavaScript ES2020 support**: Modern JavaScript features, arrow functions, template literals, etc.\n- **Type conversion**: Automatic conversion between DuckDB and JavaScript data types\n- **Error handling**: JavaScript errors are properly propagated as DuckDB exceptions\n- **State isolation**: Each function call is completely isolated, preventing state leaks between calls\n\n## Examples\n\nFor comprehensive examples of all function types and use cases, see the test file: [`test/sql/quickjs.test`](test/sql/quickjs.test)\n\n## Building\n\nTo build the extension, you first need to clone this repository and initialize the necessary git submodules:\n\n```sh\ngit clone --recursive https://github.com/your-repo/duckdb-quickjs.git\ncd duckdb-quickjs\n```\n\nIf you have already cloned the repository without the `--recursive` flag, you can initialize the submodules with:\n```sh\ngit submodule update --init --recursive\n```\n\nOnce the submodules are ready, you can build the extension using `make`:\n\n```sh\nmake\n```\n\nThe main binaries that will be built are:\n```sh\n./build/release/duckdb\n./build/release/test/unittest\n./build/release/extension/quickjs/quickjs.duckdb_extension\n```\n- `duckdb` is the binary for the DuckDB shell with the extension code automatically loaded.\n- `unittest` is the test runner for DuckDB.\n- `quickjs.duckdb_extension` is the loadable binary for the extension.\n\n## Usage\n\nLoad the extension in DuckDB:\n\n```sql\nLOAD 'path/to/quickjs.duckdb_extension';\n```\n\nThen you can use any of the functions described above.\n\n## Error Handling\n\nThe extension provides detailed error messages for JavaScript execution errors:\n\n```sql\nSELECT quickjs_eval('(a) =\u003e a.nonExistentMethod()', 1);\n-- Throws: TypeError: a.nonExistentMethod is not a function\n```\n\n## Requirements\n\n- DuckDB 1.3.1 or later\n- C++11 compatible compiler\n- CMake 3.16 or later\n\n## Running Tests\n\nTo run the SQL tests for the extension, use the following command:\n\n```sh\nmake test\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.\n\n- [DuckDB](https://github.com/duckdb/duckdb) is available under the MIT License.\n- [QuickJS-NG](https://github.com/quickjs-ng/quickjs) is available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquackscience%2Fduckdb-quickjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquackscience%2Fduckdb-quickjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquackscience%2Fduckdb-quickjs/lists"}