|
| 1 | +# VortexDuckdb |
| 2 | + |
| 3 | +This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship |
| 4 | +your own DuckDB extension. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +This extension, VortexDuckdb, allow you to ... <extension_goal>. |
| 9 | + |
| 10 | +## Building |
| 11 | + |
| 12 | +### Install required system dependencies |
| 13 | + |
| 14 | +#### MacOS |
| 15 | + |
| 16 | +```shell |
| 17 | +brew install pkg-config |
| 18 | +``` |
| 19 | + |
| 20 | +### Managing dependencies |
| 21 | + |
| 22 | +DuckDB extensions uses VCPKG for dependency management. Enabling VCPKG is very simple: follow |
| 23 | +the [installation instructions](https://vcpkg.io/en/getting-started) or just run the following: |
| 24 | + |
| 25 | +```shell |
| 26 | +git clone https://github.com/Microsoft/vcpkg.git |
| 27 | +./vcpkg/bootstrap-vcpkg.sh |
| 28 | +export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake |
| 29 | +``` |
| 30 | + |
| 31 | +Note: VCPKG is only required for extensions that want to rely on it for dependency management. If you want to develop an |
| 32 | +extension without dependencies, or want to do your own dependency management, just skip this step. Note that the example |
| 33 | +extension uses VCPKG to build with a dependency for instructive purposes, so when skipping this step the build may not |
| 34 | +work without removing the dependency. |
| 35 | + |
| 36 | +### Build steps |
| 37 | + |
| 38 | +Now to build the extension, run: |
| 39 | + |
| 40 | +```sh |
| 41 | +make |
| 42 | +``` |
| 43 | + |
| 44 | +The main binaries that will be built are: |
| 45 | + |
| 46 | +```sh |
| 47 | +./build/release/duckdb |
| 48 | +./build/release/test/unittest |
| 49 | +./build/release/extension/vortex_duckdb/vortex_duckdb.duckdb_extension |
| 50 | +``` |
| 51 | + |
| 52 | +- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded. |
| 53 | +- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary. |
| 54 | +- `vortex_duckdb.duckdb_extension` is the loadable binary as it would be distributed. |
| 55 | + |
| 56 | +## Running the extension |
| 57 | + |
| 58 | +To run the extension code, simply start the shell with `./build/release/duckdb`. |
| 59 | + |
| 60 | +Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function |
| 61 | +`vortex_duckdb()` that takes a string arguments and returns a string: |
| 62 | + |
| 63 | +``` |
| 64 | +D select vortex_duckdb('Jane') as result; |
| 65 | +┌───────────────┐ |
| 66 | +│ result │ |
| 67 | +│ varchar │ |
| 68 | +├───────────────┤ |
| 69 | +│ VortexDuckdb Jane 🐥 │ |
| 70 | +└───────────────┘ |
| 71 | +``` |
| 72 | + |
| 73 | +## Running the tests |
| 74 | + |
| 75 | +Different tests can be created for DuckDB extensions. The primary way of testing DuckDB extensions should be the SQL |
| 76 | +tests in `./test/sql`. These SQL tests can be run using: |
| 77 | + |
| 78 | +```sh |
| 79 | +make test |
| 80 | +``` |
| 81 | + |
| 82 | +### Installing the deployed binaries |
| 83 | + |
| 84 | +To install your extension binaries from S3, you will need to do two things. Firstly, DuckDB should be launched with the |
| 85 | +`allow_unsigned_extensions` option set to true. How to set this will depend on the client you're using. Some examples: |
| 86 | + |
| 87 | +CLI: |
| 88 | + |
| 89 | +```shell |
| 90 | +duckdb -unsigned |
| 91 | +``` |
| 92 | + |
| 93 | +Python: |
| 94 | + |
| 95 | +```python |
| 96 | +con = duckdb.connect(':memory:', config={'allow_unsigned_extensions': 'true'}) |
| 97 | +``` |
| 98 | + |
| 99 | +NodeJS: |
| 100 | + |
| 101 | +```js |
| 102 | +db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"}); |
| 103 | +``` |
| 104 | + |
| 105 | +Secondly, you will need to set the repository endpoint in DuckDB to the HTTP url of your bucket + version of the |
| 106 | +extension |
| 107 | +you want to install. To do this run the following SQL query in DuckDB: |
| 108 | + |
| 109 | +```sql |
| 110 | +SET |
| 111 | +custom_extension_repository='bucket.s3.eu-west-1.amazonaws.com/<your_extension_name>/latest'; |
| 112 | +``` |
| 113 | + |
| 114 | +Note that the `/latest` path will allow you to install the latest extension version available for your current version |
| 115 | +of |
| 116 | +DuckDB. To specify a specific version, you can pass the version instead. |
| 117 | + |
| 118 | +After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB: |
| 119 | + |
| 120 | +```sql |
| 121 | +INSTALL |
| 122 | +vortex_duckdb |
| 123 | +LOAD vortex_duckdb |
| 124 | +``` |
0 commit comments