├── .github └── workflows │ ├── release.yaml │ ├── rename-wheels.py │ ├── test.yaml │ └── upload-deno-assets.js ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── Makefile ├── README.md ├── VERSION ├── bindings ├── ruby │ ├── .gitignore │ ├── Gemfile │ ├── Rakefile │ ├── lib │ │ ├── sqlite_jsonschema.rb │ │ ├── version.rb │ │ └── version.rb.tmpl │ └── sqlite_jsonschema.gemspec └── sqlite-utils │ ├── .gitignore │ ├── README.md │ ├── pyproject.toml │ ├── pyproject.toml.tmpl │ └── sqlite_utils_sqlite_jsonschema │ ├── __init__.py │ ├── version.py │ └── version.py.tmpl ├── build.rs ├── deno ├── README.md ├── README.md.tmpl ├── deno.json ├── deno.json.tmpl ├── deno.lock ├── mod.ts └── test.ts ├── docs.md ├── npm ├── .gitignore ├── README.md ├── platform-package.README.md.tmpl ├── platform-package.package.json.tmpl ├── sqlite-jsonschema-darwin-arm64 │ ├── .gitignore │ ├── README.md │ ├── lib │ │ └── .gitkeep │ └── package.json ├── sqlite-jsonschema-darwin-x64 │ ├── .gitignore │ ├── README.md │ ├── lib │ │ └── .gitkeep │ └── package.json ├── sqlite-jsonschema-linux-x64 │ ├── .gitignore │ ├── README.md │ ├── lib │ │ └── .gitkeep │ └── package.json ├── sqlite-jsonschema-windows-x64 │ ├── .gitignore │ ├── README.md │ ├── lib │ │ └── .gitkeep │ └── package.json └── sqlite-jsonschema │ ├── README.md │ ├── package.json │ ├── package.json.tmpl │ ├── src │ └── index.js │ └── test.js ├── python ├── .gitignore ├── README.md ├── datasette_sqlite_jsonschema │ ├── README.md │ ├── datasette_sqlite_jsonschema │ │ ├── __init__.py │ │ └── version.py │ ├── setup.py │ └── tests │ │ └── test_sqlite_jsonschema.py └── sqlite_jsonschema │ ├── README.md │ ├── noop.c │ ├── setup.py │ └── sqlite_jsonschema │ ├── __init__.py │ └── version.py ├── scripts ├── deno_generate_package.sh ├── npm_generate_platform_packages.sh ├── publish_release.sh └── site_generate.sh ├── site ├── _config.ts ├── _data.yaml ├── _includes │ ├── base.njk │ └── navbar.njk ├── _sql.ts ├── deno.json ├── deno.lock ├── examples.md ├── index.md ├── reference.md ├── reference.md.tmpl ├── static │ ├── github-mark-white.svg │ ├── github-mark.svg │ ├── pico.min.css │ ├── script.js │ └── style.css └── usage │ ├── datasette.md │ ├── deno.md │ ├── hljs.md │ ├── loadable.md │ ├── node.md │ ├── python.md │ ├── source.md │ └── sqlite3.md ├── src ├── jsonschema.rs └── lib.rs └── tests ├── test-loadable.py └── test-python.py /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: "Release" 2 | on: 3 | release: 4 | types: [published] 5 | workflow_dispatch: 6 | permissions: 7 | contents: read 8 | jobs: 9 | build-ubuntu-extension: 10 | name: Build ubuntu 11 | runs-on: ubuntu-20.04 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions-rs/toolchain@v1 15 | with: 16 | toolchain: stable 17 | - run: make loadable-release 18 | - name: Upload artifacts 19 | uses: actions/upload-artifact@v3 20 | with: 21 | name: sqlite-jsonschema-ubuntu 22 | path: dist/release/jsonschema0.so 23 | build-ubuntu-python: 24 | runs-on: ubuntu-20.04 25 | needs: [build-ubuntu-extension] 26 | steps: 27 | - uses: actions/checkout@v3 28 | - name: Download workflow artifacts 29 | uses: actions/download-artifact@v3 30 | with: 31 | name: sqlite-jsonschema-ubuntu 32 | path: dist/release/ 33 | - uses: actions/setup-python@v3 34 | - run: pip install wheel 35 | - run: make python-release 36 | - uses: actions/upload-artifact@v3 37 | with: 38 | name: sqlite-jsonschema-ubuntu-wheels 39 | path: dist/release/wheels/*.whl 40 | build-macos-extension: 41 | name: Build macos-latest 42 | runs-on: macos-latest 43 | steps: 44 | - uses: actions/checkout@v3 45 | - uses: actions-rs/toolchain@v1 46 | with: 47 | toolchain: stable 48 | - run: make loadable-release 49 | - name: Upload artifacts 50 | uses: actions/upload-artifact@v3 51 | with: 52 | name: sqlite-jsonschema-macos 53 | path: dist/release/jsonschema0.dylib 54 | build-macos-python: 55 | runs-on: macos-latest 56 | needs: [build-macos-extension] 57 | steps: 58 | - uses: actions/checkout@v3 59 | - name: Download workflow artifacts 60 | uses: actions/download-artifact@v3 61 | with: 62 | name: sqlite-jsonschema-macos 63 | path: dist/release/ 64 | - uses: actions/setup-python@v3 65 | - run: pip install wheel 66 | - run: make python-release 67 | - uses: actions/upload-artifact@v3 68 | with: 69 | name: sqlite-jsonschema-macos-wheels 70 | path: dist/release/wheels/*.whl 71 | build-macos-arm-extension: 72 | name: Build macos-latest with arm 73 | runs-on: macos-latest 74 | steps: 75 | - uses: actions/checkout@v3 76 | - uses: actions-rs/toolchain@v1 77 | with: 78 | toolchain: stable 79 | - run: rustup target add aarch64-apple-darwin 80 | - run: make loadable-release target=aarch64-apple-darwin 81 | - name: Upload artifacts 82 | uses: actions/upload-artifact@v3 83 | with: 84 | name: sqlite-jsonschema-macos-arm 85 | path: dist/release/jsonschema0.dylib 86 | build-macos-arm-python: 87 | runs-on: macos-latest 88 | needs: [build-macos-arm-extension] 89 | steps: 90 | - uses: actions/checkout@v3 91 | - name: Download workflow artifacts 92 | uses: actions/download-artifact@v3 93 | with: 94 | name: sqlite-jsonschema-macos-arm 95 | path: dist/release/ 96 | - uses: actions/setup-python@v3 97 | - run: pip install wheel 98 | - run: make python-release IS_MACOS_ARM=1 99 | - uses: actions/upload-artifact@v3 100 | with: 101 | name: sqlite-jsonschema-macos-arm-wheels 102 | path: dist/release/wheels/*.whl 103 | build-windows-extension: 104 | name: Build windows-latest 105 | runs-on: windows-latest 106 | steps: 107 | - uses: actions/checkout@v3 108 | - uses: actions-rs/toolchain@v1 109 | with: 110 | toolchain: stable 111 | - run: make loadable-release 112 | - name: Upload artifacts 113 | uses: actions/upload-artifact@v3 114 | with: 115 | name: sqlite-jsonschema-windows 116 | path: dist/release/jsonschema0.dll 117 | build-windows-python: 118 | runs-on: windows-latest 119 | needs: [build-windows-extension] 120 | steps: 121 | - uses: actions/checkout@v3 122 | - name: Download workflow artifacts 123 | uses: actions/download-artifact@v3 124 | with: 125 | name: sqlite-jsonschema-windows 126 | path: dist/release/ 127 | - uses: actions/setup-python@v3 128 | - run: pip install wheel 129 | - run: make python-release 130 | - uses: actions/upload-artifact@v3 131 | with: 132 | name: sqlite-jsonschema-windows-wheels 133 | path: dist/release/wheels/*.whl 134 | build-datasette-sqlite-utils: 135 | runs-on: ubuntu-20.04 136 | steps: 137 | - uses: actions/checkout@v3 138 | - uses: actions/setup-python@v3 139 | - run: pip install wheel build 140 | - run: make datasette-release sqlite-utils-release 141 | - uses: actions/upload-artifact@v3 142 | with: 143 | name: sqlite-jsonschema-datasette-sqlite-utils-wheels 144 | path: dist/release/wheels/*.whl 145 | upload-extensions: 146 | name: Upload release assets 147 | needs: 148 | [ 149 | build-macos-extension, 150 | build-macos-arm-extension, 151 | build-ubuntu-extension, 152 | build-windows-extension, 153 | ] 154 | permissions: 155 | contents: write 156 | runs-on: ubuntu-latest 157 | steps: 158 | - uses: actions/checkout@v2 159 | - uses: actions/download-artifact@v2 160 | - uses: asg017/upload-spm@main 161 | id: upload-spm 162 | with: 163 | name: sqlite-jsonschema 164 | github-token: ${{ secrets.GITHUB_TOKEN }} 165 | platforms: | 166 | linux-x86_64: sqlite-jsonschema-ubuntu/* 167 | macos-x86_64: sqlite-jsonschema-macos/* 168 | macos-aarch64: sqlite-jsonschema-macos-arm/* 169 | windows-x86_64: sqlite-jsonschema-windows/* 170 | upload-deno: 171 | name: Upload Deno release assets 172 | needs: 173 | [ 174 | build-macos-extension, 175 | build-macos-arm-extension, 176 | build-ubuntu-extension, 177 | build-windows-extension, 178 | ] 179 | permissions: 180 | contents: write 181 | runs-on: ubuntu-latest 182 | steps: 183 | - uses: actions/checkout@v3 184 | - name: Download workflow artifacts 185 | uses: actions/download-artifact@v2 186 | - uses: actions/github-script@v6 187 | with: 188 | github-token: ${{ secrets.GITHUB_TOKEN }} 189 | script: | 190 | const script = require('.github/workflows/upload-deno-assets.js') 191 | await script({github, context}) 192 | upload-crate: 193 | runs-on: ubuntu-latest 194 | steps: 195 | - uses: actions/checkout@v2 196 | - uses: actions-rs/toolchain@v1 197 | with: 198 | toolchain: stable 199 | - run: cargo publish 200 | env: 201 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} 202 | upload-npm: 203 | needs: 204 | [ 205 | build-macos-extension, 206 | build-macos-arm-extension, 207 | build-ubuntu-extension, 208 | build-windows-extension, 209 | ] 210 | runs-on: ubuntu-latest 211 | steps: 212 | - uses: actions/checkout@v3 213 | - name: Download workflow artifacts 214 | uses: actions/download-artifact@v2 215 | - run: | 216 | cp sqlite-jsonschema-ubuntu/jsonschema0.so npm/sqlite-jsonschema-linux-x64/lib/jsonschema0.so 217 | cp sqlite-jsonschema-macos/jsonschema0.dylib npm/sqlite-jsonschema-darwin-x64/lib/jsonschema0.dylib 218 | cp sqlite-jsonschema-macos-arm/jsonschema0.dylib npm/sqlite-jsonschema-darwin-arm64/lib/jsonschema0.dylib 219 | cp sqlite-jsonschema-windows/jsonschema0.dll npm/sqlite-jsonschema-windows-x64/lib/jsonschema0.dll 220 | - name: Install node 221 | uses: actions/setup-node@v3 222 | with: 223 | node-version: "16" 224 | registry-url: "https://registry.npmjs.org" 225 | - name: Publish NPM sqlite-jsonschema-linux-x64 226 | working-directory: npm/sqlite-jsonschema-linux-x64 227 | run: npm publish --access public 228 | env: 229 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 230 | - name: Publish NPM sqlite-jsonschema-darwin-x64 231 | working-directory: npm/sqlite-jsonschema-darwin-x64 232 | run: npm publish --access public 233 | env: 234 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 235 | - name: Publish NPM sqlite-jsonschema-darwin-arm64 236 | working-directory: npm/sqlite-jsonschema-darwin-arm64 237 | run: npm publish --access public 238 | env: 239 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 240 | - name: Publish NPM sqlite-jsonschema-windows-x64 241 | working-directory: npm/sqlite-jsonschema-windows-x64 242 | run: npm publish --access public 243 | env: 244 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 245 | - name: Publish NPM sqlite-jsonschema 246 | working-directory: npm/sqlite-jsonschema 247 | run: npm publish --access public 248 | env: 249 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 250 | upload-gem: 251 | needs: 252 | [ 253 | build-macos-extension, 254 | build-macos-arm-extension, 255 | build-ubuntu-extension, 256 | build-windows-extension, 257 | ] 258 | permissions: 259 | contents: write 260 | runs-on: ubuntu-latest 261 | steps: 262 | - uses: actions/checkout@v2 263 | - uses: actions/download-artifact@v2 264 | - uses: ruby/setup-ruby@v1 265 | with: 266 | ruby-version: 3.2 267 | - run: | 268 | rm bindings/ruby/lib/*.{dylib,so,dll} || true 269 | cp sqlite-jsonschema-macos/*.dylib bindings/ruby/lib 270 | gem -C bindings/ruby build -o x86_64-darwin.gem sqlite_jsonschema.gemspec 271 | env: 272 | PLATFORM: x86_64-darwin 273 | - run: | 274 | rm bindings/ruby/lib/*.{dylib,so,dll} || true 275 | cp sqlite-jsonschema-macos-arm/*.dylib bindings/ruby/lib 276 | gem -C bindings/ruby build -o arm64-darwin.gem sqlite_jsonschema.gemspec 277 | env: 278 | PLATFORM: arm64-darwin 279 | - run: | 280 | rm bindings/ruby/lib/*.{dylib,so,dll} || true 281 | cp sqlite-jsonschema-ubuntu/*.so bindings/ruby/lib 282 | gem -C bindings/ruby build -o x86_64-linux.gem sqlite_jsonschema.gemspec 283 | env: 284 | PLATFORM: x86_64-linux 285 | - run: | 286 | rm bindings/ruby/lib/*.{dylib,so,dll} || true 287 | cp sqlite-jsonschema-windows/*.dll bindings/ruby/lib 288 | gem -C bindings/ruby build -o ${{ env.PLATFORM }}.gem sqlite_jsonschema.gemspec 289 | env: 290 | PLATFORM: x64-mingw32 291 | - run: | 292 | gem push bindings/ruby/x86_64-linux.gem 293 | gem push bindings/ruby/x86_64-darwin.gem 294 | gem push bindings/ruby/arm64-darwin.gem 295 | gem push bindings/ruby/x64-mingw32.gem 296 | env: 297 | GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }} 298 | upload-pypi: 299 | needs: 300 | [ 301 | build-ubuntu-python, 302 | build-macos-python, 303 | build-macos-arm-python, 304 | build-windows-python, 305 | build-datasette-sqlite-utils, 306 | ] 307 | runs-on: ubuntu-latest 308 | steps: 309 | - uses: actions/download-artifact@v3 310 | with: 311 | name: sqlite-jsonschema-windows-wheels 312 | path: dist 313 | - uses: actions/download-artifact@v3 314 | with: 315 | name: sqlite-jsonschema-ubuntu-wheels 316 | path: dist 317 | - uses: actions/download-artifact@v3 318 | with: 319 | name: sqlite-jsonschema-macos-wheels 320 | path: dist 321 | - uses: actions/download-artifact@v3 322 | with: 323 | name: sqlite-jsonschema-macos-arm-wheels 324 | path: dist 325 | - uses: actions/download-artifact@v3 326 | with: 327 | name: sqlite-jsonschema-datasette-sqlite-utils-wheels 328 | path: dist 329 | - uses: pypa/gh-action-pypi-publish@release/v1 330 | with: 331 | password: ${{ secrets.PYPI_API_TOKEN }} 332 | skip_existing: true 333 | -------------------------------------------------------------------------------- /.github/workflows/rename-wheels.py: -------------------------------------------------------------------------------- 1 | # This file is a small utility that rename all .whl files in a given directory 2 | # and "generalizes" them. The wheels made by python/sqlite_jsonschema contain the 3 | # pre-compiled sqlite extension, but those aren't bound by a specfic Python 4 | # runtime or version, that other wheels might be. So, this file will rename 5 | # those wheels to be "generalized", like replacing "c37-cp37" to "py3-none". 6 | import sys 7 | import os 8 | from pathlib import Path 9 | 10 | wheel_dir = sys.argv[1] 11 | 12 | is_macos_arm_build = '--is-macos-arm' in sys.argv 13 | 14 | for filename in os.listdir(wheel_dir): 15 | filename = Path(wheel_dir, filename) 16 | if not filename.suffix == '.whl': 17 | continue 18 | new_filename = (filename.name 19 | .replace('cp37-cp37', 'py3-none') 20 | .replace('cp38-cp38', 'py3-none') 21 | .replace('cp39-cp39', 'py3-none') 22 | .replace('cp310-cp310', 'py3-none') 23 | .replace('cp311-cp311', 'py3-none') 24 | .replace('linux_x86_64', 'manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux1_x86_64') 25 | 26 | 27 | ) 28 | if is_macos_arm_build: 29 | new_filename = new_filename.replace('macosx_12_0_universal2', 'macosx_11_0_arm64') 30 | else: 31 | new_filename = (new_filename 32 | .replace('macosx_12_0_universal2', 'macosx_10_6_x86_64') 33 | .replace('macosx_12_0_x86_64', 'macosx_10_6_x86_64') 34 | ) 35 | 36 | os.rename(filename, Path(wheel_dir, new_filename)) 37 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: "build" 2 | on: 3 | push: 4 | branches: 5 | - main 6 | permissions: 7 | contents: read 8 | jobs: 9 | build-site: 10 | permissions: 11 | pages: write 12 | id-token: write 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Clone repository 16 | uses: actions/checkout@v3 17 | 18 | - name: Setup Deno environment 19 | uses: denoland/setup-deno@v1 20 | with: 21 | deno-version: v1.30 22 | - name: Build site 23 | run: make site-build 24 | - name: Setup Pages 25 | uses: actions/configure-pages@v2 26 | - name: Upload artifact 27 | uses: actions/upload-pages-artifact@v1 28 | with: 29 | path: site/_site 30 | - name: Deploy to GitHub Pages 31 | id: deployment 32 | uses: actions/deploy-pages@v1 33 | build-ubuntu-extension: 34 | name: Building 35 | runs-on: ubuntu-20.04 36 | steps: 37 | - uses: actions/checkout@v3 38 | - uses: actions/cache@v3 39 | with: 40 | path: | 41 | ~/.cargo/bin/ 42 | ~/.cargo/registry/index/ 43 | ~/.cargo/registry/cache/ 44 | ~/.cargo/git/db/ 45 | target/ 46 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 47 | - uses: actions-rs/toolchain@v1 48 | with: 49 | toolchain: stable 50 | - run: make loadable 51 | - name: Upload artifacts 52 | uses: actions/upload-artifact@v3 53 | with: 54 | name: sqlite-jsonschema-ubuntu 55 | path: dist/debug/jsonschema0.so 56 | build-ubuntu-python: 57 | runs-on: ubuntu-20.04 58 | needs: [build-ubuntu-extension] 59 | steps: 60 | - uses: actions/checkout@v3 61 | - name: Download workflow artifacts 62 | uses: actions/download-artifact@v3 63 | with: 64 | name: sqlite-jsonschema-ubuntu 65 | path: dist/debug/ 66 | - uses: actions/setup-python@v3 67 | - run: pip install wheel 68 | - run: make python 69 | - run: make datasette 70 | - uses: actions/upload-artifact@v3 71 | with: 72 | name: sqlite-jsonschema-ubuntu-wheels 73 | path: dist/debug/wheels/*.whl 74 | test-ubuntu: 75 | runs-on: ubuntu-20.04 76 | needs: [build-ubuntu-extension, build-ubuntu-python] 77 | env: 78 | DENO_DIR: deno_cache 79 | steps: 80 | - uses: actions/checkout@v3 81 | - uses: actions/download-artifact@v3 82 | with: 83 | name: sqlite-jsonschema-ubuntu 84 | path: dist/debug/ 85 | - uses: actions/download-artifact@v3 86 | with: 87 | name: sqlite-jsonschema-ubuntu 88 | path: npm/sqlite-jsonschema-linux-x64/lib 89 | - uses: actions/download-artifact@v3 90 | with: 91 | name: sqlite-jsonschema-ubuntu-wheels 92 | path: dist/debug/ 93 | - run: pip install --find-links dist/debug/ sqlite_jsonschema 94 | - run: make test-loadable 95 | - run: make test-python 96 | # for test-npm 97 | - uses: actions/setup-node@v3 98 | with: 99 | cache: "npm" 100 | cache-dependency-path: npm/sqlite-jsonschema/package.json 101 | - run: npm install 102 | working-directory: npm/sqlite-jsonschema 103 | - run: make test-npm 104 | # for test-deno 105 | - uses: denoland/setup-deno@v1 106 | with: 107 | deno-version: v1.30 108 | - name: Cache Deno dependencies 109 | uses: actions/cache@v3 110 | with: 111 | path: ${{ env.DENO_DIR }} 112 | key: ${{ runner.os }}-${{ hashFiles('deno/deno.lock') }} 113 | - run: make test-deno 114 | env: 115 | DENO_SQLITE_JSONSCHEMA_PATH: ${{ github.workspace }}/dist/debug/jsonschema0.so 116 | build-macos-extension: 117 | name: Building macos-latest 118 | runs-on: macos-latest 119 | steps: 120 | - uses: actions/checkout@v3 121 | - uses: actions/cache@v3 122 | with: 123 | path: | 124 | ~/.cargo/bin/ 125 | ~/.cargo/registry/index/ 126 | ~/.cargo/registry/cache/ 127 | ~/.cargo/git/db/ 128 | target/ 129 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 130 | - uses: actions-rs/toolchain@v1 131 | with: 132 | toolchain: stable 133 | - run: make loadable 134 | - name: Upload artifacts 135 | uses: actions/upload-artifact@v3 136 | with: 137 | name: sqlite-jsonschema-macos 138 | path: dist/debug/jsonschema0.dylib 139 | build-macos-python: 140 | runs-on: macos-latest 141 | needs: [build-macos-extension] 142 | steps: 143 | - uses: actions/checkout@v3 144 | - name: Download workflow artifacts 145 | uses: actions/download-artifact@v3 146 | with: 147 | name: sqlite-jsonschema-macos 148 | path: dist/debug/ 149 | - uses: actions/setup-python@v3 150 | - run: pip install wheel 151 | - run: make python 152 | - run: make datasette 153 | - uses: actions/upload-artifact@v3 154 | with: 155 | name: sqlite-jsonschema-macos-wheels 156 | path: dist/debug/wheels/*.whl 157 | test-macos: 158 | runs-on: macos-latest 159 | needs: [build-macos-extension, build-macos-python] 160 | env: 161 | DENO_DIR: deno_cache 162 | steps: 163 | - uses: actions/checkout@v3 164 | - uses: actions/download-artifact@v3 165 | with: 166 | name: sqlite-jsonschema-macos 167 | path: dist/debug/ 168 | - uses: actions/download-artifact@v3 169 | with: 170 | name: sqlite-jsonschema-macos 171 | path: npm/sqlite-jsonschema-darwin-x64/lib 172 | - uses: actions/download-artifact@v3 173 | with: 174 | name: sqlite-jsonschema-macos-wheels 175 | path: dist/debug/ 176 | - run: brew install python 177 | - run: /usr/local/opt/python@3/libexec/bin/pip install --find-links dist/debug/ sqlite_jsonschema 178 | - run: make test-loadable python=/usr/local/opt/python@3/libexec/bin/python 179 | - run: make test-python python=/usr/local/opt/python@3/libexec/bin/python 180 | # for test-npm 181 | - uses: actions/setup-node@v3 182 | with: 183 | cache: "npm" 184 | cache-dependency-path: npm/sqlite-jsonschema/package.json 185 | - run: npm install 186 | working-directory: npm/sqlite-jsonschema 187 | - run: make test-npm 188 | # for test-deno 189 | - uses: denoland/setup-deno@v1 190 | with: 191 | deno-version: v1.30 192 | - name: Cache Deno dependencies 193 | uses: actions/cache@v3 194 | with: 195 | path: ${{ env.DENO_DIR }} 196 | key: ${{ runner.os }}-${{ hashFiles('deno/deno.lock') }} 197 | - run: make test-deno 198 | env: 199 | DENO_SQLITE_JSONSCHEMA_PATH: ${{ github.workspace }}/dist/debug/jsonschema0.dylib 200 | build-macos-arm-extension: 201 | name: Building macos arm extension 202 | runs-on: macos-latest 203 | steps: 204 | - uses: actions/checkout@v3 205 | - uses: actions/cache@v3 206 | with: 207 | path: | 208 | ~/.cargo/bin/ 209 | ~/.cargo/registry/index/ 210 | ~/.cargo/registry/cache/ 211 | ~/.cargo/git/db/ 212 | target/ 213 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 214 | - uses: actions-rs/toolchain@v1 215 | with: 216 | toolchain: stable 217 | - run: rustup target add aarch64-apple-darwin 218 | - run: make loadable target=aarch64-apple-darwin 219 | - name: Upload artifacts 220 | uses: actions/upload-artifact@v3 221 | with: 222 | name: sqlite-jsonschema-macos-arm 223 | path: dist/debug/jsonschema0.dylib 224 | build-macos-arm-python: 225 | runs-on: macos-latest 226 | needs: [build-macos-arm-extension] 227 | steps: 228 | - uses: actions/checkout@v3 229 | - name: Download workflow artifacts 230 | uses: actions/download-artifact@v3 231 | with: 232 | name: sqlite-jsonschema-macos-arm 233 | path: dist/debug/ 234 | - uses: actions/setup-python@v3 235 | - run: pip install wheel 236 | - run: make python IS_MACOS_ARM=1 237 | - run: make datasette 238 | - uses: actions/upload-artifact@v3 239 | with: 240 | name: sqlite-jsonschema-macos-arm-wheels 241 | path: dist/debug/wheels/*.whl 242 | build-windows-extension: 243 | name: Building windows extension 244 | runs-on: windows-latest 245 | steps: 246 | - uses: actions/checkout@v3 247 | - uses: actions/cache@v3 248 | with: 249 | path: | 250 | ~/.cargo/bin/ 251 | ~/.cargo/registry/index/ 252 | ~/.cargo/registry/cache/ 253 | ~/.cargo/git/db/ 254 | target/ 255 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 256 | - uses: actions-rs/toolchain@v1 257 | with: 258 | toolchain: stable 259 | - run: make loadable 260 | - name: Upload artifacts 261 | uses: actions/upload-artifact@v3 262 | with: 263 | name: sqlite-jsonschema-windows 264 | path: dist/debug/jsonschema0.dll 265 | build-windows-python: 266 | runs-on: windows-latest 267 | needs: [build-windows-extension] 268 | steps: 269 | - uses: actions/checkout@v3 270 | - name: Download workflow artifacts 271 | uses: actions/download-artifact@v3 272 | with: 273 | name: sqlite-jsonschema-windows 274 | path: dist/debug/ 275 | - uses: actions/setup-python@v3 276 | - run: pip install wheel 277 | - run: make python 278 | - run: make datasette 279 | - uses: actions/upload-artifact@v3 280 | with: 281 | name: sqlite-jsonschema-windows-wheels 282 | path: dist/debug/wheels/*.whl 283 | test-windows: 284 | runs-on: windows-latest 285 | needs: [build-windows-extension, build-windows-python] 286 | env: 287 | DENO_DIR: deno_cache 288 | steps: 289 | - uses: actions/checkout@v3 290 | - uses: actions/download-artifact@v3 291 | with: 292 | name: sqlite-jsonschema-windows 293 | path: dist/debug/ 294 | - uses: actions/download-artifact@v3 295 | with: 296 | name: sqlite-jsonschema-windows 297 | path: npm/sqlite-jsonschema-windows-x64/lib 298 | - uses: actions/download-artifact@v3 299 | with: 300 | name: sqlite-jsonschema-windows-wheels 301 | path: dist/debug/ 302 | - run: pip install --find-links dist/debug/ sqlite_jsonschema 303 | - run: make test-loadable 304 | - run: make test-python 305 | # for test-npm 306 | - uses: actions/setup-node@v3 307 | with: 308 | cache: "npm" 309 | cache-dependency-path: npm/sqlite-jsonschema/package.json 310 | - run: npm install 311 | working-directory: npm/sqlite-jsonschema 312 | - run: make test-npm 313 | # for test-deno 314 | - uses: denoland/setup-deno@v1 315 | with: 316 | deno-version: v1.30 317 | - name: Cache Deno dependencies 318 | uses: actions/cache@v3 319 | with: 320 | path: ${{ env.DENO_DIR }} 321 | key: ${{ runner.os }}-${{ hashFiles('deno/deno.lock') }} 322 | - run: make test-deno 323 | env: 324 | DENO_SQLITE_JSONSCHEMA_PATH: ${{ github.workspace }}/dist/debug/jsonschema0.dll 325 | upload_test_pypi: 326 | if: ${{ contains(github.event.head_commit.message, '@test_pypi') }} 327 | needs: [test-ubuntu, test-macos, test-windows, build-macos-arm-python] 328 | runs-on: ubuntu-latest 329 | steps: 330 | - uses: actions/download-artifact@v3 331 | with: 332 | name: sqlite-jsonschema-windows-wheels 333 | path: dist 334 | - uses: actions/download-artifact@v3 335 | with: 336 | name: sqlite-jsonschema-ubuntu-wheels 337 | path: dist 338 | - uses: actions/download-artifact@v3 339 | with: 340 | name: sqlite-jsonschema-macos-wheels 341 | path: dist 342 | - uses: actions/download-artifact@v3 343 | with: 344 | name: sqlite-jsonschema-macos-arm-wheels 345 | path: dist 346 | - uses: pypa/gh-action-pypi-publish@release/v1 347 | with: 348 | password: ${{ secrets.TEST_PYPI_API_TOKEN }} 349 | repository_url: https://test.pypi.org/legacy/ 350 | skip_existing: true 351 | -------------------------------------------------------------------------------- /.github/workflows/upload-deno-assets.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs").promises; 2 | 3 | module.exports = async ({ github, context }) => { 4 | const { 5 | repo: { owner, repo }, 6 | sha, 7 | } = context; 8 | console.log(process.env.GITHUB_REF); 9 | const release = await github.rest.repos.getReleaseByTag({ 10 | owner, 11 | repo, 12 | tag: process.env.GITHUB_REF.replace("refs/tags/", ""), 13 | }); 14 | console.log("release id: ", release.data.id); 15 | const release_id = release.data.id; 16 | 17 | const compiled_extensions = [ 18 | { 19 | path: "sqlite-jsonschema-macos-arm/jsonschema0.dylib", 20 | name: "deno-darwin-aarch64.jsonschema0.dylib", 21 | }, 22 | { 23 | path: "sqlite-jsonschema-macos/jsonschema0.dylib", 24 | name: "deno-darwin-x86_64.jsonschema0.dylib", 25 | }, 26 | { 27 | path: "sqlite-jsonschema-ubuntu/jsonschema0.so", 28 | name: "deno-linux-x86_64.jsonschema0.so", 29 | }, 30 | { 31 | path: "sqlite-jsonschema-windows/jsonschema0.dll", 32 | name: "deno-windows-x86_64.jsonschema0.dll", 33 | }, 34 | ]; 35 | await Promise.all( 36 | compiled_extensions.map(async ({ name, path }) => { 37 | return github.rest.repos.uploadReleaseAsset({ 38 | owner, 39 | repo, 40 | release_id, 41 | name, 42 | data: await fs.readFile(path), 43 | }); 44 | }) 45 | ); 46 | }; 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | target/ 3 | dist/ 4 | *.dylib 5 | *.so 6 | *.dll 7 | 8 | site/_site/ -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "ahash" 7 | version = "0.8.1" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "464b3811b747f8f7ebc8849c9c728c39f6ac98a055edad93baf9eb330e3f8f9d" 10 | dependencies = [ 11 | "cfg-if", 12 | "getrandom", 13 | "once_cell", 14 | "serde", 15 | "version_check", 16 | ] 17 | 18 | [[package]] 19 | name = "aho-corasick" 20 | version = "0.7.19" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" 23 | dependencies = [ 24 | "memchr", 25 | ] 26 | 27 | [[package]] 28 | name = "anyhow" 29 | version = "1.0.66" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" 32 | 33 | [[package]] 34 | name = "atty" 35 | version = "0.2.14" 36 | source = "registry+https://github.com/rust-lang/crates.io-index" 37 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 38 | dependencies = [ 39 | "hermit-abi", 40 | "libc", 41 | "winapi", 42 | ] 43 | 44 | [[package]] 45 | name = "autocfg" 46 | version = "1.1.0" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 49 | 50 | [[package]] 51 | name = "base64" 52 | version = "0.13.1" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" 55 | 56 | [[package]] 57 | name = "bindgen" 58 | version = "0.60.1" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" 61 | dependencies = [ 62 | "bitflags", 63 | "cexpr", 64 | "clang-sys", 65 | "clap", 66 | "env_logger", 67 | "lazy_static", 68 | "lazycell", 69 | "log", 70 | "peeking_take_while", 71 | "proc-macro2", 72 | "quote", 73 | "regex", 74 | "rustc-hash", 75 | "shlex", 76 | "which", 77 | ] 78 | 79 | [[package]] 80 | name = "bit-set" 81 | version = "0.5.3" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" 84 | dependencies = [ 85 | "bit-vec", 86 | ] 87 | 88 | [[package]] 89 | name = "bit-vec" 90 | version = "0.6.3" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" 93 | 94 | [[package]] 95 | name = "bitflags" 96 | version = "1.3.2" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 99 | 100 | [[package]] 101 | name = "bumpalo" 102 | version = "3.11.1" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" 105 | 106 | [[package]] 107 | name = "bytecount" 108 | version = "0.6.3" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" 111 | 112 | [[package]] 113 | name = "cc" 114 | version = "1.0.73" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" 117 | 118 | [[package]] 119 | name = "cexpr" 120 | version = "0.6.0" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" 123 | dependencies = [ 124 | "nom", 125 | ] 126 | 127 | [[package]] 128 | name = "cfg-if" 129 | version = "1.0.0" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 132 | 133 | [[package]] 134 | name = "clang-sys" 135 | version = "1.4.0" 136 | source = "registry+https://github.com/rust-lang/crates.io-index" 137 | checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" 138 | dependencies = [ 139 | "glob", 140 | "libc", 141 | "libloading", 142 | ] 143 | 144 | [[package]] 145 | name = "clap" 146 | version = "3.2.22" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" 149 | dependencies = [ 150 | "atty", 151 | "bitflags", 152 | "clap_lex", 153 | "indexmap", 154 | "strsim", 155 | "termcolor", 156 | "textwrap", 157 | ] 158 | 159 | [[package]] 160 | name = "clap_lex" 161 | version = "0.2.4" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" 164 | dependencies = [ 165 | "os_str_bytes", 166 | ] 167 | 168 | [[package]] 169 | name = "either" 170 | version = "1.8.0" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" 173 | 174 | [[package]] 175 | name = "env_logger" 176 | version = "0.9.1" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272" 179 | dependencies = [ 180 | "atty", 181 | "humantime", 182 | "log", 183 | "regex", 184 | "termcolor", 185 | ] 186 | 187 | [[package]] 188 | name = "fancy-regex" 189 | version = "0.10.0" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "0678ab2d46fa5195aaf59ad034c083d351377d4af57f3e073c074d0da3e3c766" 192 | dependencies = [ 193 | "bit-set", 194 | "regex", 195 | ] 196 | 197 | [[package]] 198 | name = "form_urlencoded" 199 | version = "1.1.0" 200 | source = "registry+https://github.com/rust-lang/crates.io-index" 201 | checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" 202 | dependencies = [ 203 | "percent-encoding", 204 | ] 205 | 206 | [[package]] 207 | name = "fraction" 208 | version = "0.12.1" 209 | source = "registry+https://github.com/rust-lang/crates.io-index" 210 | checksum = "99df8100674344d1cee346c764684f7ad688a4dcaa1a3efb2fdb45daf9acf4f9" 211 | dependencies = [ 212 | "lazy_static", 213 | "num", 214 | ] 215 | 216 | [[package]] 217 | name = "getrandom" 218 | version = "0.2.8" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" 221 | dependencies = [ 222 | "cfg-if", 223 | "js-sys", 224 | "libc", 225 | "wasi", 226 | "wasm-bindgen", 227 | ] 228 | 229 | [[package]] 230 | name = "glob" 231 | version = "0.3.0" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 234 | 235 | [[package]] 236 | name = "hashbrown" 237 | version = "0.12.3" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 240 | 241 | [[package]] 242 | name = "hermit-abi" 243 | version = "0.1.19" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 246 | dependencies = [ 247 | "libc", 248 | ] 249 | 250 | [[package]] 251 | name = "humantime" 252 | version = "2.1.0" 253 | source = "registry+https://github.com/rust-lang/crates.io-index" 254 | checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" 255 | 256 | [[package]] 257 | name = "idna" 258 | version = "0.3.0" 259 | source = "registry+https://github.com/rust-lang/crates.io-index" 260 | checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" 261 | dependencies = [ 262 | "unicode-bidi", 263 | "unicode-normalization", 264 | ] 265 | 266 | [[package]] 267 | name = "indexmap" 268 | version = "1.9.1" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" 271 | dependencies = [ 272 | "autocfg", 273 | "hashbrown", 274 | ] 275 | 276 | [[package]] 277 | name = "iso8601" 278 | version = "0.5.0" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | checksum = "2f21abb3d09069861499d93d41a970243a90e215df0cf763ac9a31b9b27178d0" 281 | dependencies = [ 282 | "nom", 283 | ] 284 | 285 | [[package]] 286 | name = "itoa" 287 | version = "1.0.4" 288 | source = "registry+https://github.com/rust-lang/crates.io-index" 289 | checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" 290 | 291 | [[package]] 292 | name = "js-sys" 293 | version = "0.3.60" 294 | source = "registry+https://github.com/rust-lang/crates.io-index" 295 | checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" 296 | dependencies = [ 297 | "wasm-bindgen", 298 | ] 299 | 300 | [[package]] 301 | name = "jsonschema" 302 | version = "0.16.1" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | checksum = "6ca9e2b45609132ae2214d50482c03aeee78826cd6fd53a8940915b81acedf16" 305 | dependencies = [ 306 | "ahash", 307 | "anyhow", 308 | "base64", 309 | "bytecount", 310 | "fancy-regex", 311 | "fraction", 312 | "iso8601", 313 | "itoa", 314 | "lazy_static", 315 | "memchr", 316 | "num-cmp", 317 | "parking_lot", 318 | "percent-encoding", 319 | "regex", 320 | "serde", 321 | "serde_json", 322 | "time", 323 | "url", 324 | "uuid", 325 | ] 326 | 327 | [[package]] 328 | name = "lazy_static" 329 | version = "1.4.0" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 332 | 333 | [[package]] 334 | name = "lazycell" 335 | version = "1.3.0" 336 | source = "registry+https://github.com/rust-lang/crates.io-index" 337 | checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" 338 | 339 | [[package]] 340 | name = "libc" 341 | version = "0.2.135" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" 344 | 345 | [[package]] 346 | name = "libloading" 347 | version = "0.7.3" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" 350 | dependencies = [ 351 | "cfg-if", 352 | "winapi", 353 | ] 354 | 355 | [[package]] 356 | name = "lock_api" 357 | version = "0.4.9" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" 360 | dependencies = [ 361 | "autocfg", 362 | "scopeguard", 363 | ] 364 | 365 | [[package]] 366 | name = "log" 367 | version = "0.4.17" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 370 | dependencies = [ 371 | "cfg-if", 372 | ] 373 | 374 | [[package]] 375 | name = "memchr" 376 | version = "2.5.0" 377 | source = "registry+https://github.com/rust-lang/crates.io-index" 378 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 379 | 380 | [[package]] 381 | name = "minimal-lexical" 382 | version = "0.2.1" 383 | source = "registry+https://github.com/rust-lang/crates.io-index" 384 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 385 | 386 | [[package]] 387 | name = "nom" 388 | version = "7.1.1" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" 391 | dependencies = [ 392 | "memchr", 393 | "minimal-lexical", 394 | ] 395 | 396 | [[package]] 397 | name = "num" 398 | version = "0.4.0" 399 | source = "registry+https://github.com/rust-lang/crates.io-index" 400 | checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" 401 | dependencies = [ 402 | "num-bigint", 403 | "num-complex", 404 | "num-integer", 405 | "num-iter", 406 | "num-rational", 407 | "num-traits", 408 | ] 409 | 410 | [[package]] 411 | name = "num-bigint" 412 | version = "0.4.3" 413 | source = "registry+https://github.com/rust-lang/crates.io-index" 414 | checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" 415 | dependencies = [ 416 | "autocfg", 417 | "num-integer", 418 | "num-traits", 419 | ] 420 | 421 | [[package]] 422 | name = "num-cmp" 423 | version = "0.1.0" 424 | source = "registry+https://github.com/rust-lang/crates.io-index" 425 | checksum = "63335b2e2c34fae2fb0aa2cecfd9f0832a1e24b3b32ecec612c3426d46dc8aaa" 426 | 427 | [[package]] 428 | name = "num-complex" 429 | version = "0.4.2" 430 | source = "registry+https://github.com/rust-lang/crates.io-index" 431 | checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" 432 | dependencies = [ 433 | "num-traits", 434 | ] 435 | 436 | [[package]] 437 | name = "num-integer" 438 | version = "0.1.45" 439 | source = "registry+https://github.com/rust-lang/crates.io-index" 440 | checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" 441 | dependencies = [ 442 | "autocfg", 443 | "num-traits", 444 | ] 445 | 446 | [[package]] 447 | name = "num-iter" 448 | version = "0.1.43" 449 | source = "registry+https://github.com/rust-lang/crates.io-index" 450 | checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" 451 | dependencies = [ 452 | "autocfg", 453 | "num-integer", 454 | "num-traits", 455 | ] 456 | 457 | [[package]] 458 | name = "num-rational" 459 | version = "0.4.1" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" 462 | dependencies = [ 463 | "autocfg", 464 | "num-bigint", 465 | "num-integer", 466 | "num-traits", 467 | ] 468 | 469 | [[package]] 470 | name = "num-traits" 471 | version = "0.2.15" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 474 | dependencies = [ 475 | "autocfg", 476 | ] 477 | 478 | [[package]] 479 | name = "num_threads" 480 | version = "0.1.6" 481 | source = "registry+https://github.com/rust-lang/crates.io-index" 482 | checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" 483 | dependencies = [ 484 | "libc", 485 | ] 486 | 487 | [[package]] 488 | name = "once_cell" 489 | version = "1.15.0" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" 492 | 493 | [[package]] 494 | name = "os_str_bytes" 495 | version = "6.3.0" 496 | source = "registry+https://github.com/rust-lang/crates.io-index" 497 | checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" 498 | 499 | [[package]] 500 | name = "parking_lot" 501 | version = "0.12.1" 502 | source = "registry+https://github.com/rust-lang/crates.io-index" 503 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 504 | dependencies = [ 505 | "lock_api", 506 | "parking_lot_core", 507 | ] 508 | 509 | [[package]] 510 | name = "parking_lot_core" 511 | version = "0.9.4" 512 | source = "registry+https://github.com/rust-lang/crates.io-index" 513 | checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" 514 | dependencies = [ 515 | "cfg-if", 516 | "libc", 517 | "redox_syscall", 518 | "smallvec", 519 | "windows-sys", 520 | ] 521 | 522 | [[package]] 523 | name = "peeking_take_while" 524 | version = "0.1.2" 525 | source = "registry+https://github.com/rust-lang/crates.io-index" 526 | checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" 527 | 528 | [[package]] 529 | name = "percent-encoding" 530 | version = "2.2.0" 531 | source = "registry+https://github.com/rust-lang/crates.io-index" 532 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" 533 | 534 | [[package]] 535 | name = "proc-macro2" 536 | version = "1.0.47" 537 | source = "registry+https://github.com/rust-lang/crates.io-index" 538 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 539 | dependencies = [ 540 | "unicode-ident", 541 | ] 542 | 543 | [[package]] 544 | name = "quote" 545 | version = "1.0.21" 546 | source = "registry+https://github.com/rust-lang/crates.io-index" 547 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 548 | dependencies = [ 549 | "proc-macro2", 550 | ] 551 | 552 | [[package]] 553 | name = "redox_syscall" 554 | version = "0.2.16" 555 | source = "registry+https://github.com/rust-lang/crates.io-index" 556 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 557 | dependencies = [ 558 | "bitflags", 559 | ] 560 | 561 | [[package]] 562 | name = "regex" 563 | version = "1.6.0" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" 566 | dependencies = [ 567 | "aho-corasick", 568 | "memchr", 569 | "regex-syntax", 570 | ] 571 | 572 | [[package]] 573 | name = "regex-syntax" 574 | version = "0.6.27" 575 | source = "registry+https://github.com/rust-lang/crates.io-index" 576 | checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" 577 | 578 | [[package]] 579 | name = "rustc-hash" 580 | version = "1.1.0" 581 | source = "registry+https://github.com/rust-lang/crates.io-index" 582 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 583 | 584 | [[package]] 585 | name = "ryu" 586 | version = "1.0.11" 587 | source = "registry+https://github.com/rust-lang/crates.io-index" 588 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 589 | 590 | [[package]] 591 | name = "scopeguard" 592 | version = "1.1.0" 593 | source = "registry+https://github.com/rust-lang/crates.io-index" 594 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 595 | 596 | [[package]] 597 | name = "serde" 598 | version = "1.0.147" 599 | source = "registry+https://github.com/rust-lang/crates.io-index" 600 | checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" 601 | dependencies = [ 602 | "serde_derive", 603 | ] 604 | 605 | [[package]] 606 | name = "serde_derive" 607 | version = "1.0.147" 608 | source = "registry+https://github.com/rust-lang/crates.io-index" 609 | checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" 610 | dependencies = [ 611 | "proc-macro2", 612 | "quote", 613 | "syn", 614 | ] 615 | 616 | [[package]] 617 | name = "serde_json" 618 | version = "1.0.87" 619 | source = "registry+https://github.com/rust-lang/crates.io-index" 620 | checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" 621 | dependencies = [ 622 | "itoa", 623 | "ryu", 624 | "serde", 625 | ] 626 | 627 | [[package]] 628 | name = "shlex" 629 | version = "1.1.0" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" 632 | 633 | [[package]] 634 | name = "smallvec" 635 | version = "1.10.0" 636 | source = "registry+https://github.com/rust-lang/crates.io-index" 637 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 638 | 639 | [[package]] 640 | name = "sqlite-jsonschema" 641 | version = "0.2.3" 642 | dependencies = [ 643 | "jsonschema", 644 | "serde_json", 645 | "sqlite-loadable", 646 | ] 647 | 648 | [[package]] 649 | name = "sqlite-loadable" 650 | version = "0.0.5" 651 | source = "registry+https://github.com/rust-lang/crates.io-index" 652 | checksum = "a916b7bb8738eef189dea88731b619b80bf3f62b3acf05138fa43fbf8621cc94" 653 | dependencies = [ 654 | "bitflags", 655 | "serde", 656 | "serde_json", 657 | "sqlite-loadable-macros", 658 | "sqlite3ext-sys", 659 | ] 660 | 661 | [[package]] 662 | name = "sqlite-loadable-macros" 663 | version = "0.0.2" 664 | source = "registry+https://github.com/rust-lang/crates.io-index" 665 | checksum = "f98bc75a8d6fd24f6a2cfea34f28758780fa17279d3051eec926efa381971e48" 666 | dependencies = [ 667 | "proc-macro2", 668 | "quote", 669 | "syn", 670 | ] 671 | 672 | [[package]] 673 | name = "sqlite3ext-sys" 674 | version = "0.0.1" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "3afdc2b3dc08f16d6eecf8aa07d19975a268603ab1cca67d3f9b4172c507cf16" 677 | dependencies = [ 678 | "bindgen", 679 | "cc", 680 | ] 681 | 682 | [[package]] 683 | name = "strsim" 684 | version = "0.10.0" 685 | source = "registry+https://github.com/rust-lang/crates.io-index" 686 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 687 | 688 | [[package]] 689 | name = "syn" 690 | version = "1.0.103" 691 | source = "registry+https://github.com/rust-lang/crates.io-index" 692 | checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" 693 | dependencies = [ 694 | "proc-macro2", 695 | "quote", 696 | "unicode-ident", 697 | ] 698 | 699 | [[package]] 700 | name = "termcolor" 701 | version = "1.1.3" 702 | source = "registry+https://github.com/rust-lang/crates.io-index" 703 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 704 | dependencies = [ 705 | "winapi-util", 706 | ] 707 | 708 | [[package]] 709 | name = "textwrap" 710 | version = "0.15.1" 711 | source = "registry+https://github.com/rust-lang/crates.io-index" 712 | checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" 713 | 714 | [[package]] 715 | name = "time" 716 | version = "0.3.16" 717 | source = "registry+https://github.com/rust-lang/crates.io-index" 718 | checksum = "0fab5c8b9980850e06d92ddbe3ab839c062c801f3927c0fb8abd6fc8e918fbca" 719 | dependencies = [ 720 | "libc", 721 | "num_threads", 722 | "serde", 723 | "time-core", 724 | "time-macros", 725 | ] 726 | 727 | [[package]] 728 | name = "time-core" 729 | version = "0.1.0" 730 | source = "registry+https://github.com/rust-lang/crates.io-index" 731 | checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" 732 | 733 | [[package]] 734 | name = "time-macros" 735 | version = "0.2.5" 736 | source = "registry+https://github.com/rust-lang/crates.io-index" 737 | checksum = "65bb801831d812c562ae7d2bfb531f26e66e4e1f6b17307ba4149c5064710e5b" 738 | dependencies = [ 739 | "time-core", 740 | ] 741 | 742 | [[package]] 743 | name = "tinyvec" 744 | version = "1.6.0" 745 | source = "registry+https://github.com/rust-lang/crates.io-index" 746 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 747 | dependencies = [ 748 | "tinyvec_macros", 749 | ] 750 | 751 | [[package]] 752 | name = "tinyvec_macros" 753 | version = "0.1.0" 754 | source = "registry+https://github.com/rust-lang/crates.io-index" 755 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 756 | 757 | [[package]] 758 | name = "unicode-bidi" 759 | version = "0.3.8" 760 | source = "registry+https://github.com/rust-lang/crates.io-index" 761 | checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" 762 | 763 | [[package]] 764 | name = "unicode-ident" 765 | version = "1.0.5" 766 | source = "registry+https://github.com/rust-lang/crates.io-index" 767 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 768 | 769 | [[package]] 770 | name = "unicode-normalization" 771 | version = "0.1.22" 772 | source = "registry+https://github.com/rust-lang/crates.io-index" 773 | checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" 774 | dependencies = [ 775 | "tinyvec", 776 | ] 777 | 778 | [[package]] 779 | name = "url" 780 | version = "2.3.1" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" 783 | dependencies = [ 784 | "form_urlencoded", 785 | "idna", 786 | "percent-encoding", 787 | ] 788 | 789 | [[package]] 790 | name = "uuid" 791 | version = "1.2.1" 792 | source = "registry+https://github.com/rust-lang/crates.io-index" 793 | checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" 794 | 795 | [[package]] 796 | name = "version_check" 797 | version = "0.9.4" 798 | source = "registry+https://github.com/rust-lang/crates.io-index" 799 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 800 | 801 | [[package]] 802 | name = "wasi" 803 | version = "0.11.0+wasi-snapshot-preview1" 804 | source = "registry+https://github.com/rust-lang/crates.io-index" 805 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 806 | 807 | [[package]] 808 | name = "wasm-bindgen" 809 | version = "0.2.83" 810 | source = "registry+https://github.com/rust-lang/crates.io-index" 811 | checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" 812 | dependencies = [ 813 | "cfg-if", 814 | "wasm-bindgen-macro", 815 | ] 816 | 817 | [[package]] 818 | name = "wasm-bindgen-backend" 819 | version = "0.2.83" 820 | source = "registry+https://github.com/rust-lang/crates.io-index" 821 | checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" 822 | dependencies = [ 823 | "bumpalo", 824 | "log", 825 | "once_cell", 826 | "proc-macro2", 827 | "quote", 828 | "syn", 829 | "wasm-bindgen-shared", 830 | ] 831 | 832 | [[package]] 833 | name = "wasm-bindgen-macro" 834 | version = "0.2.83" 835 | source = "registry+https://github.com/rust-lang/crates.io-index" 836 | checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" 837 | dependencies = [ 838 | "quote", 839 | "wasm-bindgen-macro-support", 840 | ] 841 | 842 | [[package]] 843 | name = "wasm-bindgen-macro-support" 844 | version = "0.2.83" 845 | source = "registry+https://github.com/rust-lang/crates.io-index" 846 | checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" 847 | dependencies = [ 848 | "proc-macro2", 849 | "quote", 850 | "syn", 851 | "wasm-bindgen-backend", 852 | "wasm-bindgen-shared", 853 | ] 854 | 855 | [[package]] 856 | name = "wasm-bindgen-shared" 857 | version = "0.2.83" 858 | source = "registry+https://github.com/rust-lang/crates.io-index" 859 | checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" 860 | 861 | [[package]] 862 | name = "which" 863 | version = "4.3.0" 864 | source = "registry+https://github.com/rust-lang/crates.io-index" 865 | checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" 866 | dependencies = [ 867 | "either", 868 | "libc", 869 | "once_cell", 870 | ] 871 | 872 | [[package]] 873 | name = "winapi" 874 | version = "0.3.9" 875 | source = "registry+https://github.com/rust-lang/crates.io-index" 876 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 877 | dependencies = [ 878 | "winapi-i686-pc-windows-gnu", 879 | "winapi-x86_64-pc-windows-gnu", 880 | ] 881 | 882 | [[package]] 883 | name = "winapi-i686-pc-windows-gnu" 884 | version = "0.4.0" 885 | source = "registry+https://github.com/rust-lang/crates.io-index" 886 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 887 | 888 | [[package]] 889 | name = "winapi-util" 890 | version = "0.1.5" 891 | source = "registry+https://github.com/rust-lang/crates.io-index" 892 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 893 | dependencies = [ 894 | "winapi", 895 | ] 896 | 897 | [[package]] 898 | name = "winapi-x86_64-pc-windows-gnu" 899 | version = "0.4.0" 900 | source = "registry+https://github.com/rust-lang/crates.io-index" 901 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 902 | 903 | [[package]] 904 | name = "windows-sys" 905 | version = "0.42.0" 906 | source = "registry+https://github.com/rust-lang/crates.io-index" 907 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 908 | dependencies = [ 909 | "windows_aarch64_gnullvm", 910 | "windows_aarch64_msvc", 911 | "windows_i686_gnu", 912 | "windows_i686_msvc", 913 | "windows_x86_64_gnu", 914 | "windows_x86_64_gnullvm", 915 | "windows_x86_64_msvc", 916 | ] 917 | 918 | [[package]] 919 | name = "windows_aarch64_gnullvm" 920 | version = "0.42.0" 921 | source = "registry+https://github.com/rust-lang/crates.io-index" 922 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 923 | 924 | [[package]] 925 | name = "windows_aarch64_msvc" 926 | version = "0.42.0" 927 | source = "registry+https://github.com/rust-lang/crates.io-index" 928 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 929 | 930 | [[package]] 931 | name = "windows_i686_gnu" 932 | version = "0.42.0" 933 | source = "registry+https://github.com/rust-lang/crates.io-index" 934 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 935 | 936 | [[package]] 937 | name = "windows_i686_msvc" 938 | version = "0.42.0" 939 | source = "registry+https://github.com/rust-lang/crates.io-index" 940 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 941 | 942 | [[package]] 943 | name = "windows_x86_64_gnu" 944 | version = "0.42.0" 945 | source = "registry+https://github.com/rust-lang/crates.io-index" 946 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 947 | 948 | [[package]] 949 | name = "windows_x86_64_gnullvm" 950 | version = "0.42.0" 951 | source = "registry+https://github.com/rust-lang/crates.io-index" 952 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 953 | 954 | [[package]] 955 | name = "windows_x86_64_msvc" 956 | version = "0.42.0" 957 | source = "registry+https://github.com/rust-lang/crates.io-index" 958 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 959 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sqlite-jsonschema" 3 | version = "0.2.3" 4 | edition = "2021" 5 | authors = ["Alex Garcia "] 6 | description = "A SQLite extension for validating JSON documents" 7 | homepage = "https://github.com/asg017/sqlite-jsonschema" 8 | repository = "https://github.com/asg017/sqlite-jsonschema" 9 | keywords = ["sqlite", "sqlite-extension"] 10 | license = "MIT/Apache-2.0" 11 | 12 | [dependencies] 13 | sqlite-loadable = "0.0.5" 14 | jsonschema = {version="0.16.1", default-features = false} 15 | serde_json = "1.0.87" 16 | 17 | [lib] 18 | crate-type=["lib", "staticlib", "cdylib"] 19 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Alex Garcia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | VERSION=$(shell cat VERSION) 4 | 5 | ifeq ($(shell uname -s),Darwin) 6 | CONFIG_DARWIN=y 7 | else ifeq ($(OS),Windows_NT) 8 | CONFIG_WINDOWS=y 9 | else 10 | CONFIG_LINUX=y 11 | endif 12 | 13 | LIBRARY_PREFIX=lib 14 | ifdef CONFIG_DARWIN 15 | LOADABLE_EXTENSION=dylib 16 | endif 17 | 18 | ifdef CONFIG_LINUX 19 | LOADABLE_EXTENSION=so 20 | endif 21 | 22 | 23 | ifdef CONFIG_WINDOWS 24 | LOADABLE_EXTENSION=dll 25 | LIBRARY_PREFIX= 26 | endif 27 | 28 | prefix=dist 29 | TARGET_LOADABLE=$(prefix)/debug/jsonschema0.$(LOADABLE_EXTENSION) 30 | TARGET_LOADABLE_RELEASE=$(prefix)/release/jsonschema0.$(LOADABLE_EXTENSION) 31 | 32 | TARGET_STATIC=$(prefix)/debug/jsonschema0.a 33 | TARGET_STATIC_RELEASE=$(prefix)/release/jsonschema0.a 34 | 35 | TARGET_WHEELS=$(prefix)/debug/wheels 36 | TARGET_WHEELS_RELEASE=$(prefix)/release/wheels 37 | 38 | INTERMEDIATE_PYPACKAGE_EXTENSION=python/sqlite_jsonschema/sqlite_jsonschema/jsonschema0.$(LOADABLE_EXTENSION) 39 | 40 | ifdef target 41 | CARGO_TARGET=--target=$(target) 42 | BUILT_LOCATION=target/$(target)/debug/$(LIBRARY_PREFIX)sqlite_jsonschema.$(LOADABLE_EXTENSION) 43 | BUILT_LOCATION_RELEASE=target/$(target)/release/$(LIBRARY_PREFIX)sqlite_jsonschema.$(LOADABLE_EXTENSION) 44 | else 45 | CARGO_TARGET= 46 | BUILT_LOCATION=target/debug/$(LIBRARY_PREFIX)sqlite_jsonschema.$(LOADABLE_EXTENSION) 47 | BUILT_LOCATION_RELEASE=target/release/$(LIBRARY_PREFIX)sqlite_jsonschema.$(LOADABLE_EXTENSION) 48 | endif 49 | 50 | ifdef python 51 | PYTHON=$(python) 52 | else 53 | PYTHON=python3 54 | endif 55 | 56 | ifdef IS_MACOS_ARM 57 | RENAME_WHEELS_ARGS=--is-macos-arm 58 | else 59 | RENAME_WHEELS_ARGS= 60 | endif 61 | 62 | $(prefix): 63 | mkdir -p $(prefix)/debug 64 | mkdir -p $(prefix)/release 65 | 66 | $(TARGET_WHEELS): $(prefix) 67 | mkdir -p $(TARGET_WHEELS) 68 | 69 | $(TARGET_WHEELS_RELEASE): $(prefix) 70 | mkdir -p $(TARGET_WHEELS_RELEASE) 71 | 72 | $(TARGET_LOADABLE): $(prefix) $(shell find . -type f -name '*.rs') 73 | cargo build $(CARGO_TARGET) 74 | cp $(BUILT_LOCATION) $@ 75 | 76 | $(TARGET_LOADABLE_RELEASE): $(prefix) $(shell find . -type f -name '*.rs') 77 | cargo build --release $(CARGO_TARGET) 78 | cp $(BUILT_LOCATION_RELEASE) $@ 79 | 80 | python: $(TARGET_WHEELS) $(TARGET_LOADABLE) python/sqlite_jsonschema/setup.py python/sqlite_jsonschema/sqlite_jsonschema/__init__.py .github/workflows/rename-wheels.py 81 | cp $(TARGET_LOADABLE) $(INTERMEDIATE_PYPACKAGE_EXTENSION) 82 | rm $(TARGET_WHEELS)/sqlite_jsonschema* || true 83 | pip3 wheel python/sqlite_jsonschema/ -w $(TARGET_WHEELS) 84 | python3 .github/workflows/rename-wheels.py $(TARGET_WHEELS) $(RENAME_WHEELS_ARGS) 85 | 86 | python-release: $(TARGET_LOADABLE_RELEASE) $(TARGET_WHEELS_RELEASE) python/sqlite_jsonschema/setup.py python/sqlite_jsonschema/sqlite_jsonschema/__init__.py .github/workflows/rename-wheels.py 87 | cp $(TARGET_LOADABLE_RELEASE) $(INTERMEDIATE_PYPACKAGE_EXTENSION) 88 | rm $(TARGET_WHEELS_RELEASE)/sqlite_jsonschema* || true 89 | pip3 wheel python/sqlite_jsonschema/ -w $(TARGET_WHEELS_RELEASE) 90 | python3 .github/workflows/rename-wheels.py $(TARGET_WHEELS_RELEASE) $(RENAME_WHEELS_ARGS) 91 | 92 | datasette: $(TARGET_WHEELS) python/datasette_sqlite_jsonschema/setup.py python/datasette_sqlite_jsonschema/datasette_sqlite_jsonschema/__init__.py 93 | rm $(TARGET_WHEELS)/datasette* || true 94 | pip3 wheel python/datasette_sqlite_jsonschema/ --no-deps -w $(TARGET_WHEELS) 95 | 96 | datasette-release: $(TARGET_WHEELS_RELEASE) python/datasette_sqlite_jsonschema/setup.py python/datasette_sqlite_jsonschema/datasette_sqlite_jsonschema/__init__.py 97 | rm $(TARGET_WHEELS_RELEASE)/datasette* || true 98 | pip3 wheel python/datasette_sqlite_jsonschema/ --no-deps -w $(TARGET_WHEELS_RELEASE) 99 | 100 | bindings/sqlite-utils/pyproject.toml: bindings/sqlite-utils/pyproject.toml.tmpl VERSION 101 | VERSION=$(VERSION) envsubst < $< > $@ 102 | echo "✅ generated $@" 103 | 104 | bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py: bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py.tmpl VERSION 105 | VERSION=$(VERSION) envsubst < $< > $@ 106 | echo "✅ generated $@" 107 | 108 | sqlite-utils: $(TARGET_WHEELS) bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py 109 | python3 -m build bindings/sqlite-utils -w -o $(TARGET_WHEELS) 110 | 111 | sqlite-utils-release: $(TARGET_WHEELS) bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py 112 | python3 -m build bindings/sqlite-utils -w -o $(TARGET_WHEELS_RELEASE) 113 | 114 | npm: VERSION npm/platform-package.README.md.tmpl npm/platform-package.package.json.tmpl npm/sqlite-jsonschema/package.json.tmpl scripts/npm_generate_platform_packages.sh 115 | scripts/npm_generate_platform_packages.sh 116 | 117 | deno: VERSION deno/deno.json.tmpl 118 | scripts/deno_generate_package.sh 119 | 120 | Cargo.toml: VERSION 121 | cargo set-version `cat VERSION` 122 | 123 | python/sqlite_jsonschema/sqlite_jsonschema/version.py: VERSION 124 | printf '__version__ = "%s"\n__version_info__ = tuple(__version__.split("."))\n' `cat VERSION` > $@ 125 | 126 | python/datasette_sqlite_jsonschema/datasette_sqlite_jsonschema/version.py: VERSION 127 | printf '__version__ = "%s"\n__version_info__ = tuple(__version__.split("."))\n' `cat VERSION` > $@ 128 | 129 | bindings/ruby/lib/version.rb: bindings/ruby/lib/version.rb.tmpl VERSION 130 | VERSION=$(VERSION) envsubst < $< > $@ 131 | 132 | ruby: bindings/ruby/lib/version.rb 133 | 134 | version: 135 | make Cargo.toml 136 | make python/sqlite_jsonschema/sqlite_jsonschema/version.py 137 | make python/datasette_sqlite_jsonschema/datasette_sqlite_jsonschema/version.py 138 | make bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py 139 | make npm 140 | make deno 141 | make ruby 142 | 143 | site-build: 144 | scripts/site_generate.sh 145 | deno task -c site/deno.json build 146 | 147 | format: 148 | cargo fmt 149 | 150 | sqlite-jsonschema.h: cbindgen.toml 151 | rustup run nightly cbindgen --config $< -o $@ 152 | 153 | release: $(TARGET_LOADABLE_RELEASE) $(TARGET_STATIC_RELEASE) 154 | 155 | loadable: $(TARGET_LOADABLE) 156 | loadable-release: $(TARGET_LOADABLE_RELEASE) 157 | 158 | static: $(TARGET_STATIC) 159 | static-release: $(TARGET_STATIC_RELEASE) 160 | 161 | debug: loadable static python datasette 162 | release: loadable-release static-release python-release datasette-release 163 | 164 | clean: 165 | rm dist/* 166 | cargo clean 167 | 168 | test-loadable: 169 | $(PYTHON) tests/test-loadable.py 170 | 171 | test-python: 172 | $(PYTHON) tests/test-python.py 173 | 174 | test-npm: 175 | node npm/sqlite-jsonschema/test.js 176 | 177 | test-deno: 178 | deno task --config deno/deno.json test 179 | 180 | test: 181 | make test-loadable 182 | make test-python 183 | make test-npm 184 | make test-deno 185 | 186 | publish-release: 187 | ./scripts/publish_release.sh 188 | 189 | .PHONY: clean \ 190 | test test-loadable test-python test-npm \ 191 | loadable loadable-release \ 192 | python python-release \ 193 | datasette datasette-release \ 194 | sqlite-utils sqlite-utils-release \ 195 | static static-release \ 196 | debug release \ 197 | format version publish-release \ 198 | deno npm ruby \ 199 | site-serve site-build 200 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sqlite-jsonschema 2 | 3 | A SQLite extension for validating JSON objects with [JSON Schema](https://json-schema.org/). Based on [`sqlite-loadable-rs`](https://github.com/asg017/sqlite-loadable-rs) and the [`jsonschema` crate](https://crates.io/crates/jsonschema). 4 | 5 | If your company or organization finds this library useful, consider [supporting my work](#supporting)! 6 | 7 | ## Usage 8 | 9 | ```sql 10 | .load ./jsonschema0 11 | select jsonschema_matches('{"maxLength": 5}', json_quote('alex')); 12 | ``` 13 | 14 | Use with SQLite's [`CHECK` constraints](https://www.sqlite.org/lang_createtable.html#check_constraints) to validate JSON columns before inserting into a table. 15 | 16 | ```sql 17 | create table students( 18 | -- ensure that JSON objects stored in the data column have "firstName" strings, 19 | -- "lastName" strings, and "age" integers that are greater than 0. 20 | data json check ( 21 | jsonschema_matches( 22 | json(' 23 | { 24 | "type": "object", 25 | "properties": { 26 | "firstName": { 27 | "type": "string" 28 | }, 29 | "lastName": { 30 | "type": "string" 31 | }, 32 | "age": { 33 | "type": "integer", 34 | "minimum": 0 35 | } 36 | } 37 | } 38 | '), 39 | data 40 | ) 41 | ) 42 | ); 43 | 44 | insert into students(data) 45 | values ('{"firstName": "Alex", "lastName": "Garcia", "age": 100}'); 46 | -- ✓ 47 | 48 | 49 | insert into students(data) 50 | values ('{"firstName": "Alex", "lastName": "Garcia", "age": -1}'); 51 | -- Runtime error: CHECK constraint failed: jsonschema_matches 52 | 53 | ``` 54 | 55 | Find all the values in a column that don't match a JSON Schema. 56 | 57 | ```sql 58 | select 59 | rowid, 60 | jsonschema_matches( 61 | '{ 62 | "type": "array", 63 | "items": { 64 | "type": "number" 65 | } 66 | }', 67 | foo 68 | ) as valid 69 | from bar 70 | where not valid; 71 | ``` 72 | 73 | ## Installing 74 | 75 | | Language | Install | | 76 | | -------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 77 | | Python | `pip install sqlite-jsonschema` | [![PyPI](https://img.shields.io/pypi/v/sqlite-jsonschema.svg?color=blue&logo=python&logoColor=white)](https://pypi.org/project/sqlite-jsonschema/) | 78 | | Datasette | `datasette install datasette-sqlite-jsonschema` | [![Datasette](https://img.shields.io/pypi/v/datasette-sqlite-jsonschema.svg?color=B6B6D9&label=Datasette+plugin&logoColor=white&logo=python)](https://datasette.io/plugins/datasette-sqlite-jsonschema) | 79 | | Node.js | `npm install sqlite-jsonschema` | [![npm](https://img.shields.io/npm/v/sqlite-jsonschema.svg?color=green&logo=nodedotjs&logoColor=white)](https://www.npmjs.com/package/sqlite-jsonschema) | 80 | | Deno | [`deno.land/x/sqlite_jsonschema`](https://deno.land/x/sqlite_jsonschema) | [![deno.land/x release](https://img.shields.io/github/v/release/asg017/sqlite-jsonschema?color=fef8d2&include_prereleases&label=deno.land%2Fx&logo=deno)](https://deno.land/x/sqlite_jsonschema) | 81 | | Ruby | `gem install sqlite-jsonschema` | ![Gem](https://img.shields.io/gem/v/sqlite-jsonschema?color=red&logo=rubygems&logoColor=white) | 82 | | Github Release | | ![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/asg017/sqlite-jsonschema?color=lightgrey&include_prereleases&label=Github+release&logo=github) | 83 | | Rust | `cargo add sqlite-jsonschema` | [![Crates.io](https://img.shields.io/crates/v/sqlite-jsonschema?logo=rust)](https://crates.io/crates/sqlite-jsonschema) | 84 | 85 | 89 | 90 | `sqlite-jsonschema` is distributed on pip, npm, and https://deno.land/x for Python, Node.js, and Deno programmers. There are also pre-built extensions available for use in other environments. 91 | 92 | ### Python 93 | 94 | For Python developers, use the [`sqlite-jsonschema` Python package](https://pypi.org/package/sqlite-jsonschema/): 95 | 96 | ``` 97 | pip install sqlite-jsonschema 98 | ``` 99 | 100 | The `sqlite-jsonschema` extension can then be loaded into a [`sqlite3` Connection object](https://docs.python.org/3/library/sqlite3.html#connection-objects). 101 | 102 | ```python 103 | import sqlite3 104 | import sqlite_jsonschema 105 | 106 | db = sqlite3.connect(':memory:') 107 | sqlite_jsonschema.load(db) 108 | db.execute('select jsonschema_version(), jsonschema()').fetchone() 109 | ``` 110 | 111 | See [_Using `sqlite-jsonschema` with Python_](https://alexgarcia.jsonschema/sqlite-jsonschema/usage/python.html) for details. 112 | 113 | ### Node.js 114 | 115 | For Node.js developers, use the [`sqlite-jsonschema` NPM package](https://www.npmjs.com/package/sqlite-jsonschema): 116 | 117 | ``` 118 | npm install sqlite-jsonschema 119 | ``` 120 | 121 | The `sqlite-jsonschema` extension can then be loaded into a [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3) or [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3) connection. 122 | 123 | ```javascript 124 | import Database from "better-sqlite3"; 125 | import * as sqlite_jsonschema from "sqlite-jsonschema"; 126 | 127 | const db = new Database(":memory:"); 128 | 129 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 130 | 131 | const version = db.prepare("select jsonschema_version()").pluck().get(); 132 | console.log(version); // "v0.2.0" 133 | ``` 134 | 135 | See [_Using `sqlite-jsonschema` with Node.js_](https://alexgarcia.jsonschema/sqlite-jsonschema/usage/node.html) for details. 136 | 137 | ### Deno 138 | 139 | For [Deno](https://deno.land/) developers, use the [x/sqlite_jsonschema](https://deno.land/x/sqlite_jsonschema@v0.2.2) Deno module with [`x/sqlite3`](https://deno.land/x/sqlite3@0.8.1). 140 | 141 | ```javascript 142 | import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts"; 143 | import * as sqlite_jsonschema from "https://deno.land/x/sqlite_jsonschema/mod.ts"; 144 | 145 | const db = new Database(":memory:"); 146 | 147 | db.enableLoadExtension = true; 148 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 149 | 150 | const [version] = db 151 | .prepare("select jsonschema_version()") 152 | .value<[string]>()!; 153 | 154 | console.log(version); 155 | ``` 156 | 157 | See [_Using `sqlite-jsonschema` with Deno_](https://alexgarcia.jsonschema/sqlite-jsonschema/usage/deno.html) for details. 158 | 159 | ### Datasette 160 | 161 | For [Datasette](https://datasette.io/), use the [`datasette-sqlite-jsonschema` plugin](https://datasette.io/plugins/datasette-sqlite-jsonschema) to include `sqlite-jsonschema` functions to your Datasette instances. 162 | 163 | ``` 164 | datasette install datasette-sqlite-jsonschema 165 | ``` 166 | 167 | See [_Using `sqlite-jsonschema` with Datasette_](https://alexgarcia.jsonschema/sqlite-jsonschema/usage/datasette.html) for details. 168 | 169 | ### `sqlite3` CLI 170 | 171 | For [the `sqlite3` CLI](https://sqlite.org/cli.html), either [download a pre-compiled extension from the Releases page](https://github.com/asg017/sqlite-jsonschema/releases) or [build it yourself](#building-from-source). Then use the [`.load` dot command](https://sqlite.org/cli.html#loading_extensions). 172 | 173 | ```sql 174 | .load ./jsonschema0 175 | select jsonschema_version(); 176 | 'v0.2.1' 177 | ``` 178 | 179 | ### As a loadable extension 180 | 181 | If you're using `sqlite-jsonschema` in a different way from those listed above, then [download a pre-compiled extension from the Releases page](https://github.com/asg017/sqlite-jsonschema/releases) and load it into your environment. Download the `jsonschema0.dylib` (for MacOS), `jsonschema0.so` (Linux), or `jsonschema0.dll` (Windows) file from a release and load it into your SQLite environment. 182 | 183 | > **Note:** 184 | > The `0` in the filename (`jsonschema0.dylib`/ `jsonschema0.so`/`jsonschema0.dll`) denotes the major version of `sqlite-jsonschema`. Currently `sqlite-jsonschema` is pre v1, so expect breaking changes in future versions. 185 | 186 | Chances are there is some method called "loadExtension" or "load_extension" in the SQLite client library you are using. Alternatively, as a last resort, use [the `load_extension()` SQL function](https://www.sqlite.org/lang_corefunc.html#load_extension). 187 | 188 | ### Building from source 189 | 190 | Make sure you have [Rust](https://www.rust-lang.org/tools/install), make, and a C compiler installed. Then `git clone` this repository and run `make loadable-release`. 191 | 192 | ``` 193 | git clone https://github.com/asg017/sqlite-jsonschema.git 194 | cd sqlite-jsonschema 195 | make loadable-release 196 | ``` 197 | 198 | Once complete, your compiled extension will appear under `dist/release/`, either as `jsonschema0.so`, `jsonschema0.dylib`, or `jsonschema0.dll`, depending on your operating system. 199 | 200 | ## Documentation 201 | 202 | See [the full API Reference](https://alexgarcia.jsonschema/sqlite-jsonschema/reference.html) for every `sqlite-jsonschema` SQL function. 203 | 204 | ## Supporting 205 | 206 | I (Alex 👋🏼) spent a lot of time and energy on this project and [many other open source projects](https://github.com/asg017?tab=repositories&q=&type=&language=&sort=stargazers). If your company or organization uses this library (or you're feeling generous), then please [consider supporting my work](https://alexgarcia.jsonschema/work.html), or share this project with a friend! 207 | 208 | ## See also 209 | 210 | - [`sqlite-xsv`](https://github.com/asg017/sqlite-xsv), A SQLite extension for working with CSVs 211 | - [`sqlite-http`](https://github.com/asg017/sqlite-http), A SQLite extension for making HTTP requests 212 | - [`sqlite-loadable-rs`](https://github.com/asg017/sqlite-loadable-rs), A framework for writing SQLite extensions in Rust 213 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.2.3 -------------------------------------------------------------------------------- /bindings/ruby/.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | -------------------------------------------------------------------------------- /bindings/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 4 | 5 | gemspec 6 | -------------------------------------------------------------------------------- /bindings/ruby/Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | task :default => :spec 3 | -------------------------------------------------------------------------------- /bindings/ruby/lib/sqlite_jsonschema.rb: -------------------------------------------------------------------------------- 1 | require "version" 2 | 3 | module SqliteJsonschema 4 | class Error < StandardError; end 5 | def self.jsonschema_loadable_path 6 | File.expand_path('../jsonschema0', __FILE__) 7 | end 8 | def self.load(db) 9 | db.load_extension(self.jsonschema_loadable_path) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /bindings/ruby/lib/version.rb: -------------------------------------------------------------------------------- 1 | # automatically generated, do not edit by hand. 2 | module SqliteJsonschema 3 | VERSION = "0.2.3" 4 | end 5 | -------------------------------------------------------------------------------- /bindings/ruby/lib/version.rb.tmpl: -------------------------------------------------------------------------------- 1 | # automatically generated, do not edit by hand. 2 | module SqliteJsonschema 3 | VERSION = "${VERSION}" 4 | end 5 | -------------------------------------------------------------------------------- /bindings/ruby/sqlite_jsonschema.gemspec: -------------------------------------------------------------------------------- 1 | 2 | lib = File.expand_path("../lib", __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require "version" 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "sqlite-jsonschema" 8 | spec.version = SqliteJsonschema::VERSION 9 | spec.authors = ["Alex Garcia"] 10 | spec.email = ["alexsebastian.garcia@gmail.com"] 11 | 12 | spec.summary = "a" 13 | spec.description = "b" 14 | spec.homepage = "https://github.com/asg017/sqlite-jsonschema" 15 | spec.license = "MIT" 16 | 17 | # The --platform flag would work in most cases, but on a GH action 18 | # linux runner, it would set platform to "ruby" and not "x86-linux". 19 | # Setting this to Gem::Platform::CURRENT 20 | spec.platform = ENV['PLATFORM'] 21 | 22 | if spec.respond_to?(:metadata) 23 | 24 | spec.metadata["homepage_uri"] = spec.homepage 25 | spec.metadata["source_code_uri"] = spec.homepage 26 | spec.metadata["changelog_uri"] = spec.homepage 27 | else 28 | raise "RubyGems 2.0 or newer is required to protect against " \ 29 | "public gem pushes." 30 | end 31 | 32 | spec.files = Dir["lib/*.rb"] + Dir.glob('lib/*.{so,dylib,dll}') 33 | 34 | spec.require_paths = ["lib"] 35 | 36 | spec.add_development_dependency "bundler", "~> 1.17" 37 | spec.add_development_dependency "rake", "~> 10.0" 38 | end 39 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/README.md: -------------------------------------------------------------------------------- 1 | # `sqlite-utils-sqlite-jsonschema` 2 | 3 | A `sqlite-utils` plugin that registers the `sqlite-jsonschema` extension. 4 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "sqlite-utils-sqlite-jsonschema" 3 | version = "0.2.3" 4 | description = "TODO" 5 | readme = "README.md" 6 | authors = [{name = "Alex Garcia"}] 7 | license = {text = "Apache-2.0"} 8 | classifiers = [] 9 | 10 | dependencies = [ 11 | "sqlite-utils", 12 | "sqlite-jsonschema" 13 | ] 14 | 15 | [project.urls] 16 | Homepage = "https://github.com/asg017/sqlite-jsonschema" 17 | Changelog = "https://github.com/asg017/sqlite-jsonschema/releases" 18 | Issues = "https://github.com/asg017/sqlite-jsonschema/issues" 19 | 20 | [project.entry-points.sqlite_utils] 21 | sqlite_jsonschema = "sqlite_utils_sqlite_jsonschema" 22 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/pyproject.toml.tmpl: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "sqlite-utils-sqlite-jsonschema" 3 | version = "${VERSION}" 4 | description = "TODO" 5 | readme = "README.md" 6 | authors = [{name = "Alex Garcia"}] 7 | license = {text = "Apache-2.0"} 8 | classifiers = [] 9 | 10 | dependencies = [ 11 | "sqlite-utils", 12 | "sqlite-jsonschema" 13 | ] 14 | 15 | [project.urls] 16 | Homepage = "https://github.com/asg017/sqlite-jsonschema" 17 | Changelog = "https://github.com/asg017/sqlite-jsonschema/releases" 18 | Issues = "https://github.com/asg017/sqlite-jsonschema/issues" 19 | 20 | [project.entry-points.sqlite_utils] 21 | sqlite_jsonschema = "sqlite_utils_sqlite_jsonschema" 22 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/__init__.py: -------------------------------------------------------------------------------- 1 | from sqlite_utils import hookimpl 2 | import sqlite_jsonschema 3 | 4 | from sqlite_utils_sqlite_jsonschema.version import __version_info__, __version__ 5 | 6 | 7 | @hookimpl 8 | def prepare_connection(conn): 9 | conn.enable_load_extension(True) 10 | sqlite_jsonschema.load(conn) 11 | conn.enable_load_extension(False) 12 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.2.3" 2 | __version_info__ = tuple(__version__.split(".")) 3 | -------------------------------------------------------------------------------- /bindings/sqlite-utils/sqlite_utils_sqlite_jsonschema/version.py.tmpl: -------------------------------------------------------------------------------- 1 | __version__ = "${VERSION}" 2 | __version_info__ = tuple(__version__.split(".")) 3 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use std::process::Command; 2 | fn main() { 3 | let output = Command::new("git") 4 | .args(["rev-parse", "HEAD"]) 5 | .output() 6 | .unwrap(); 7 | let git_hash = String::from_utf8(output.stdout).unwrap(); 8 | println!("cargo:rustc-env=GIT_HASH={}", git_hash); 9 | } 10 | -------------------------------------------------------------------------------- /deno/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # `x/sqlite_jsonschema` Deno Module 4 | 5 | [![Tags](https://img.shields.io/github/release/asg017/sqlite-jsonschema)](https://github.com/asg017/sqlite-jsonschema/releases) 6 | [![Doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/sqlite-jsonschema@0.2.3/mod.ts) 7 | 8 | The [`sqlite-jsonschema`](https://github.com/asg017/sqlite-jsonschema) SQLite extension is available to Deno developers with the [`x/sqlite_jsonschema`](https://deno.land/x/sqlite-jsonschema) Deno module. It works with [`x/sqlite3`](https://deno.land/x/sqlite3), the fastest and native Deno SQLite3 module. 9 | 10 | ```js 11 | import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts"; 12 | import * as sqlite_jsonschema from "https://deno.land/x/sqlite_jsonschema@v0.2.3/mod.ts"; 13 | 14 | const db = new Database(":memory:"); 15 | 16 | db.enableLoadExtension = true; 17 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 18 | 19 | const [version] = db 20 | .prepare("select jsonschema_version()") 21 | .value<[string]>()!; 22 | 23 | console.log(version); 24 | 25 | ``` 26 | 27 | Like `x/sqlite3`, `x/sqlite_jsonschema` requires network and filesystem permissions to download and cache the pre-compiled SQLite extension for your machine. Though `x/sqlite3` already requires `--allow-ffi` and `--unstable`, so you might as well use `--allow-all`/`-A`. 28 | 29 | ```bash 30 | deno run -A --unstable 31 | ``` 32 | 33 | `x/sqlite_jsonschema` does not work with [`x/sqlite`](https://deno.land/x/sqlite@v3.7.0), which is a WASM-based Deno SQLite module that does not support loading extensions. 34 | -------------------------------------------------------------------------------- /deno/README.md.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | # `x/sqlite_jsonschema` Deno Module 4 | 5 | [![Tags](https://img.shields.io/github/release/asg017/sqlite-jsonschema)](https://github.com/asg017/sqlite-jsonschema/releases) 6 | [![Doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/sqlite-jsonschema@${VERSION}/mod.ts) 7 | 8 | The [`sqlite-jsonschema`](https://github.com/asg017/sqlite-jsonschema) SQLite extension is available to Deno developers with the [`x/sqlite_jsonschema`](https://deno.land/x/sqlite-jsonschema) Deno module. It works with [`x/sqlite3`](https://deno.land/x/sqlite3), the fastest and native Deno SQLite3 module. 9 | 10 | ```js 11 | import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts"; 12 | import * as sqlite_jsonschema from "https://deno.land/x/sqlite_jsonschema@v${VERSION}/mod.ts"; 13 | 14 | const db = new Database(":memory:"); 15 | 16 | db.enableLoadExtension = true; 17 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 18 | 19 | const [version] = db 20 | .prepare("select jsonschema_version()") 21 | .value<[string]>()!; 22 | 23 | console.log(version); 24 | 25 | ``` 26 | 27 | Like `x/sqlite3`, `x/sqlite_jsonschema` requires network and filesystem permissions to download and cache the pre-compiled SQLite extension for your machine. Though `x/sqlite3` already requires `--allow-ffi` and `--unstable`, so you might as well use `--allow-all`/`-A`. 28 | 29 | ```bash 30 | deno run -A --unstable 31 | ``` 32 | 33 | `x/sqlite_jsonschema` does not work with [`x/sqlite`](https://deno.land/x/sqlite@v3.7.0), which is a WASM-based Deno SQLite module that does not support loading extensions. 34 | -------------------------------------------------------------------------------- /deno/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqlite-jsonschema", 3 | "version": "0.2.3", 4 | "github": "https://github.com/asg017/sqlite-jsonschema", 5 | "tasks": { 6 | "test": "deno test --unstable -A test.ts" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /deno/deno.json.tmpl: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sqlite-jsonschema", 3 | "version": "${VERSION}", 4 | "github": "https://github.com/asg017/${PACKAGE_NAME}", 5 | "tasks": { 6 | "test": "deno test --unstable -A test.ts" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /deno/deno.lock: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2", 3 | "remote": { 4 | "https://deno.land/std@0.152.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74", 5 | "https://deno.land/std@0.152.0/_util/os.ts": "3b4c6e27febd119d36a416d7a97bd3b0251b77c88942c8f16ee5953ea13e2e49", 6 | "https://deno.land/std@0.152.0/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3", 7 | "https://deno.land/std@0.152.0/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09", 8 | "https://deno.land/std@0.152.0/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b", 9 | "https://deno.land/std@0.152.0/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633", 10 | "https://deno.land/std@0.152.0/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee", 11 | "https://deno.land/std@0.152.0/path/mod.ts": "56fec03ad0ebd61b6ab39ddb9b0ddb4c4a5c9f2f4f632e09dd37ec9ebfd722ac", 12 | "https://deno.land/std@0.152.0/path/posix.ts": "c1f7afe274290ea0b51da07ee205653b2964bd74909a82deb07b69a6cc383aaa", 13 | "https://deno.land/std@0.152.0/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9", 14 | "https://deno.land/std@0.152.0/path/win32.ts": "bd7549042e37879c68ff2f8576a25950abbfca1d696d41d82c7bca0b7e6f452c", 15 | "https://deno.land/std@0.176.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462", 16 | "https://deno.land/std@0.176.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", 17 | "https://deno.land/std@0.176.0/encoding/hex.ts": "50f8c95b52eae24395d3dfcb5ec1ced37c5fe7610ef6fffdcc8b0fdc38e3b32f", 18 | "https://deno.land/std@0.176.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471", 19 | "https://deno.land/std@0.176.0/fs/_util.ts": "65381f341af1ff7f40198cee15c20f59951ac26e51ddc651c5293e24f9ce6f32", 20 | "https://deno.land/std@0.176.0/fs/copy.ts": "14214efd94fc3aa6db1e4af2b4b9578e50f7362b7f3725d5a14ad259a5df26c8", 21 | "https://deno.land/std@0.176.0/fs/empty_dir.ts": "c3d2da4c7352fab1cf144a1ecfef58090769e8af633678e0f3fabaef98594688", 22 | "https://deno.land/std@0.176.0/fs/ensure_dir.ts": "724209875497a6b4628dfb256116e5651c4f7816741368d6c44aab2531a1e603", 23 | "https://deno.land/std@0.176.0/fs/ensure_file.ts": "c38602670bfaf259d86ca824a94e6cb9e5eb73757fefa4ebf43a90dd017d53d9", 24 | "https://deno.land/std@0.176.0/fs/ensure_link.ts": "c0f5b2f0ec094ed52b9128eccb1ee23362a617457aa0f699b145d4883f5b2fb4", 25 | "https://deno.land/std@0.176.0/fs/ensure_symlink.ts": "2955cc8332aeca9bdfefd05d8d3976b94e282b0f353392a71684808ed2ffdd41", 26 | "https://deno.land/std@0.176.0/fs/eol.ts": "f1f2eb348a750c34500741987b21d65607f352cf7205f48f4319d417fff42842", 27 | "https://deno.land/std@0.176.0/fs/exists.ts": "b8c8a457b71e9d7f29b9d2f87aad8dba2739cbe637e8926d6ba6e92567875f8e", 28 | "https://deno.land/std@0.176.0/fs/expand_glob.ts": "45d17e89796a24bd6002e4354eda67b4301bb8ba67d2cac8453cdabccf1d9ab0", 29 | "https://deno.land/std@0.176.0/fs/mod.ts": "bc3d0acd488cc7b42627044caf47d72019846d459279544e1934418955ba4898", 30 | "https://deno.land/std@0.176.0/fs/move.ts": "4cb47f880e3f0582c55e71c9f8b1e5e8cfaacb5e84f7390781dd563b7298ec19", 31 | "https://deno.land/std@0.176.0/fs/walk.ts": "ea95ffa6500c1eda6b365be488c056edc7c883a1db41ef46ec3bf057b1c0fe32", 32 | "https://deno.land/std@0.176.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", 33 | "https://deno.land/std@0.176.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", 34 | "https://deno.land/std@0.176.0/path/_util.ts": "d7abb1e0dea065f427b89156e28cdeb32b045870acdf865833ba808a73b576d0", 35 | "https://deno.land/std@0.176.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", 36 | "https://deno.land/std@0.176.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1", 37 | "https://deno.land/std@0.176.0/path/mod.ts": "4b83694ac500d7d31b0cdafc927080a53dc0c3027eb2895790fb155082b0d232", 38 | "https://deno.land/std@0.176.0/path/posix.ts": "8b7c67ac338714b30c816079303d0285dd24af6b284f7ad63da5b27372a2c94d", 39 | "https://deno.land/std@0.176.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", 40 | "https://deno.land/std@0.176.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", 41 | "https://deno.land/std@0.177.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471", 42 | "https://deno.land/std@0.177.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", 43 | "https://deno.land/std@0.177.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", 44 | "https://deno.land/std@0.177.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab", 45 | "https://deno.land/x/plug@1.0.1/deps.ts": "35ea2acd5e3e11846817a429b7ef4bec47b80f2d988f5d63797147134cbd35c2", 46 | "https://deno.land/x/plug@1.0.1/download.ts": "8d6a023ade0806a0653b48cd5f6f8b15fcfaa1dbf2aa1f4bc90fc5732d27b144", 47 | "https://deno.land/x/plug@1.0.1/mod.ts": "5dec80ee7a3a325be45c03439558531bce7707ac118f4376cebbd6740ff24bfb", 48 | "https://deno.land/x/plug@1.0.1/types.ts": "d8eb738fc6ed883e6abf77093442c2f0b71af9090f15c7613621d4039e410ee1", 49 | "https://deno.land/x/plug@1.0.1/util.ts": "5ba8127b9adc36e070b9e22971fb8106869eea1741f452a87b4861e574f13481", 50 | "https://deno.land/x/sqlite3@0.8.0/deno.json": "61fbd0665a1b48f5e0f1773371d49b776f559cd6c3747a4e674adc3eb423686c", 51 | "https://deno.land/x/sqlite3@0.8.0/deps.ts": "722c865b9cef27b4cde0bb1ac9ebb08e94c43ad090a7313cea576658ff1e3bb0", 52 | "https://deno.land/x/sqlite3@0.8.0/mod.ts": "d41b8b30e1b20b537ef4d78cae98d90f6bd65c727b64aa1a18bffbb28f7d6ec3", 53 | "https://deno.land/x/sqlite3@0.8.0/src/blob.ts": "a956fc0cf4a8c7a21dc3fcb71a07ef773bcd08b5fd72e8ace89b1bfbd031bf06", 54 | "https://deno.land/x/sqlite3@0.8.0/src/constants.ts": "85fd27aa6e199093f25f5f437052e16fd0e0870b96ca9b24a98e04ddc8b7d006", 55 | "https://deno.land/x/sqlite3@0.8.0/src/database.ts": "c68c7fdfa7548000ea7e194360cdce86b81b667aab6b0778ea7ed9b74a37b7cb", 56 | "https://deno.land/x/sqlite3@0.8.0/src/ffi.ts": "d5d5e3b4524cf0b980d23e57b08f75dc0debc7af2e93ff8b00cdc5af52637b31", 57 | "https://deno.land/x/sqlite3@0.8.0/src/statement.ts": "0b2b3c8b5564ad3c35f2c7d57607e5755c38b23b835e9a46aa1002e68e6ec3a2", 58 | "https://deno.land/x/sqlite3@0.8.0/src/util.ts": "9627ebecc7a5eb250d2df9386a456a9a9ed7842a20fe32be1ee6b7c663c77bd3" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /deno/mod.ts: -------------------------------------------------------------------------------- 1 | import { download } from "https://deno.land/x/plug@1.0.1/mod.ts"; 2 | import meta from "./deno.json" assert { type: "json" }; 3 | 4 | const BASE = `${meta.github}/releases/download/v${meta.version}`; 5 | 6 | // Similar to https://github.com/denodrivers/sqlite3/blob/f7529897720631c2341b713f0d78d4d668593ea9/src/ffi.ts#L561 7 | let path: string; 8 | try { 9 | const customPath = Deno.env.get("DENO_SQLITE_JSONSCHEMA_PATH"); 10 | if (customPath) path = customPath; 11 | else { 12 | path = await download({ 13 | url: { 14 | darwin: { 15 | aarch64: `${BASE}/deno-darwin-aarch64.jsonschema0.dylib`, 16 | x86_64: `${BASE}/deno-darwin-x86_64.jsonschema0.dylib`, 17 | }, 18 | windows: { 19 | x86_64: `${BASE}/deno-windows-x86_64.jsonschema0.dll`, 20 | }, 21 | linux: { 22 | x86_64: `${BASE}/deno-linux-x86_64.jsonschema0.so`, 23 | }, 24 | }, 25 | suffixes: { 26 | darwin: "", 27 | linux: "", 28 | windows: "", 29 | }, 30 | }); 31 | } 32 | } catch (e) { 33 | if (e instanceof Deno.errors.PermissionDenied) { 34 | throw e; 35 | } 36 | 37 | const error = new Error("Failed to load sqlite-jsonschema extension"); 38 | error.cause = e; 39 | 40 | throw error; 41 | } 42 | 43 | /** 44 | * Returns the full path to the compiled sqlite-jsonschema extension. 45 | * Caution: this will not be named "jsonschem0.dylib|so|dll", since plug will 46 | * replace the name with a hash. 47 | */ 48 | export function getLoadablePath(): string { 49 | return path; 50 | } 51 | 52 | /** 53 | * Entrypoint name for the sqlite-jsonschema extension. 54 | */ 55 | export const entrypoint = "sqlite3_jsonschema_init"; 56 | 57 | interface Db { 58 | // after https://deno.land/x/sqlite3@0.8.0/mod.ts?s=Database#method_loadExtension_0 59 | loadExtension(file: string, entrypoint?: string | undefined): void; 60 | } 61 | /** 62 | * Loads the sqlite-jsonschema extension on the given sqlite3 database. 63 | */ 64 | export function load(db: Db): void { 65 | db.loadExtension(path, entrypoint); 66 | } 67 | -------------------------------------------------------------------------------- /deno/test.ts: -------------------------------------------------------------------------------- 1 | import * as sqlite_jsonschema from "./mod.ts"; 2 | import meta from "./deno.json" assert { type: "json" }; 3 | 4 | import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts"; 5 | import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts"; 6 | 7 | Deno.test("x/sqlite3", (t) => { 8 | const db = new Database(":memory:"); 9 | 10 | db.enableLoadExtension = true; 11 | sqlite_jsonschema.load(db); 12 | 13 | const [version] = db 14 | .prepare("select jsonschema_version()") 15 | .value<[string]>()!; 16 | 17 | assertEquals(version[0], "v"); 18 | assertEquals(version.substring(1), meta.version); 19 | 20 | db.close(); 21 | }); 22 | -------------------------------------------------------------------------------- /docs.md: -------------------------------------------------------------------------------- 1 | # `sqlite-jsonschema` Documentation 2 | 3 | A full reference to every function and module that `sqlite-jsonschema` offers. 4 | 5 | As a reminder, `sqlite-jsonschema` follows semver and is pre v1, so breaking changes are to be expected. 6 | 7 | ## API Reference 8 | 9 |

jsonschema_matches(schema, document)

10 | 11 | Returns `1` if the given `document` matches the given `schema`, where `schema` is a valid JSON Schema. Returns `0` otherwise. 12 | 13 | ```sql 14 | select jsonschema_matches('{"maxLength": 5}', json_quote('alex')); -- 1 15 | select jsonschema_matches('{"maxLength": 5}', json_quote('alexxx')); -- 0 16 | 17 | ``` 18 | 19 |

jsonschema_version()

20 | 21 | Returns the semver version string of the current version of `sqlite-jsonschema`. 22 | 23 | ```sql 24 | select jsonschema_version(); -- 'v0.1.0' 25 | ``` 26 | 27 |

jsonschema_debug()

28 | 29 | Returns a debug string of various info about `sqlite-jsonschema`, including 30 | the version string, build date, and commit hash. 31 | 32 | ```sql 33 | select jsonschema_debug(); 34 | 'Version: v0.1.0 35 | Source: 247dca8f4cea1abdc30ed3e852c3e5b71374c177' 36 | ``` 37 | -------------------------------------------------------------------------------- /npm/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | 132 | # not needed for libraries, right? running into some issues in ci with this, so gonna yeet 133 | package-lock.json -------------------------------------------------------------------------------- /npm/README.md: -------------------------------------------------------------------------------- 1 | # sqlite-jsonschema on npm 2 | 3 | `sqlite-jsonschema` is also available for download through [`npm`](https://www.npmjs.com/) for Node.js developers. See the [`sqlite-jsonschema` NPM package README](./sqlite-jsonschema/README.md) for details. 4 | 5 | The other NPM packages in this folder (`sqlite-jsonschema-darwin-x64`, `sqlite-jsonschema-windows-x64` etc.) are autogenerated platform-specific packages. See [Supported Platforms](./sqlite-jsonschema/README.md#supported-platforms) for details. 6 | -------------------------------------------------------------------------------- /npm/platform-package.README.md.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | # ${PACKAGE_NAME} 4 | 5 | A `${PACKAGE_NAME_BASE}` platform-specific package for `${PLATFORM_OS}-${PLATFORM_ARCH}`. 6 | 7 | When `${PACKAGE_NAME_BASE}` is installed and the host computer has a `${PLATFORM_OS}` operating system with `${PLATFORM_ARCH}` architecture, then this package is downloaded with the pre-compiled SQLite extension bundled under `lib/${EXTENSION_NAME}.${EXTENSION_SUFFIX}`. At runtime, the `${PACKAGE_NAME_BASE}` package will resolve to this platform-specific package for use with [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3)' or [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3). 8 | 9 | See the `${PACKAGE_NAME_BASE}` package for more details. -------------------------------------------------------------------------------- /npm/platform-package.package.json.tmpl: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "${PACKAGE_NAME}", 4 | "version": "${VERSION}", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/asg017/${PACKAGE_NAME_BASE}.git", 8 | "directory": "npm/${PACKAGE_NAME}" 9 | }, 10 | "author": "Alex Garcia ", 11 | "os": [ 12 | "${PLATFORM_OS}" 13 | ], 14 | "cpu": [ 15 | "${PLATFORM_ARCH}" 16 | ] 17 | } -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-arm64/.gitignore: -------------------------------------------------------------------------------- 1 | # generated by npm_generate_platform_packages.sh 2 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-arm64/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # sqlite-jsonschema-darwin-arm64 4 | 5 | A `sqlite-jsonschema` platform-specific package for `darwin-arm64`. 6 | 7 | When `sqlite-jsonschema` is installed and the host computer has a `darwin` operating system with `arm64` architecture, then this package is downloaded with the pre-compiled SQLite extension bundled under `lib/jsonschema0.dylib`. At runtime, the `sqlite-jsonschema` package will resolve to this platform-specific package for use with [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3)' or [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3). 8 | 9 | See the `sqlite-jsonschema` package for more details. -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-arm64/lib/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asg017/sqlite-jsonschema/fadd55ddc28537f5f8769205e2c0798dfb854b79/npm/sqlite-jsonschema-darwin-arm64/lib/.gitkeep -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-arm64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "sqlite-jsonschema-darwin-arm64", 4 | "version": "0.2.3", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/asg017/sqlite-jsonschema.git", 8 | "directory": "npm/sqlite-jsonschema-darwin-arm64" 9 | }, 10 | "author": "Alex Garcia ", 11 | "os": [ 12 | "darwin" 13 | ], 14 | "cpu": [ 15 | "arm64" 16 | ] 17 | } -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-x64/.gitignore: -------------------------------------------------------------------------------- 1 | # generated by npm_generate_platform_packages.sh 2 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-x64/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # sqlite-jsonschema-darwin-x64 4 | 5 | A `sqlite-jsonschema` platform-specific package for `darwin-x64`. 6 | 7 | When `sqlite-jsonschema` is installed and the host computer has a `darwin` operating system with `x64` architecture, then this package is downloaded with the pre-compiled SQLite extension bundled under `lib/jsonschema0.dylib`. At runtime, the `sqlite-jsonschema` package will resolve to this platform-specific package for use with [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3)' or [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3). 8 | 9 | See the `sqlite-jsonschema` package for more details. -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-x64/lib/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asg017/sqlite-jsonschema/fadd55ddc28537f5f8769205e2c0798dfb854b79/npm/sqlite-jsonschema-darwin-x64/lib/.gitkeep -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-darwin-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "sqlite-jsonschema-darwin-x64", 4 | "version": "0.2.3", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/asg017/sqlite-jsonschema.git", 8 | "directory": "npm/sqlite-jsonschema-darwin-x64" 9 | }, 10 | "author": "Alex Garcia ", 11 | "os": [ 12 | "darwin" 13 | ], 14 | "cpu": [ 15 | "x64" 16 | ] 17 | } -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-linux-x64/.gitignore: -------------------------------------------------------------------------------- 1 | # generated by npm_generate_platform_packages.sh 2 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-linux-x64/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # sqlite-jsonschema-linux-x64 4 | 5 | A `sqlite-jsonschema` platform-specific package for `linux-x64`. 6 | 7 | When `sqlite-jsonschema` is installed and the host computer has a `linux` operating system with `x64` architecture, then this package is downloaded with the pre-compiled SQLite extension bundled under `lib/jsonschema0.so`. At runtime, the `sqlite-jsonschema` package will resolve to this platform-specific package for use with [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3)' or [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3). 8 | 9 | See the `sqlite-jsonschema` package for more details. -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-linux-x64/lib/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asg017/sqlite-jsonschema/fadd55ddc28537f5f8769205e2c0798dfb854b79/npm/sqlite-jsonschema-linux-x64/lib/.gitkeep -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-linux-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "sqlite-jsonschema-linux-x64", 4 | "version": "0.2.3", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/asg017/sqlite-jsonschema.git", 8 | "directory": "npm/sqlite-jsonschema-linux-x64" 9 | }, 10 | "author": "Alex Garcia ", 11 | "os": [ 12 | "linux" 13 | ], 14 | "cpu": [ 15 | "x64" 16 | ] 17 | } -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-windows-x64/.gitignore: -------------------------------------------------------------------------------- 1 | # generated by npm_generate_platform_packages.sh 2 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-windows-x64/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # sqlite-jsonschema-windows-x64 4 | 5 | A `sqlite-jsonschema` platform-specific package for `windows-x64`. 6 | 7 | When `sqlite-jsonschema` is installed and the host computer has a `windows` operating system with `x64` architecture, then this package is downloaded with the pre-compiled SQLite extension bundled under `lib/jsonschema0.dll`. At runtime, the `sqlite-jsonschema` package will resolve to this platform-specific package for use with [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3)' or [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3). 8 | 9 | See the `sqlite-jsonschema` package for more details. -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-windows-x64/lib/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asg017/sqlite-jsonschema/fadd55ddc28537f5f8769205e2c0798dfb854b79/npm/sqlite-jsonschema-windows-x64/lib/.gitkeep -------------------------------------------------------------------------------- /npm/sqlite-jsonschema-windows-x64/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "sqlite-jsonschema-windows-x64", 4 | "version": "0.2.3", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/asg017/sqlite-jsonschema.git", 8 | "directory": "npm/sqlite-jsonschema-windows-x64" 9 | }, 10 | "author": "Alex Garcia ", 11 | "os": [ 12 | "windows" 13 | ], 14 | "cpu": [ 15 | "x64" 16 | ] 17 | } -------------------------------------------------------------------------------- /npm/sqlite-jsonschema/README.md: -------------------------------------------------------------------------------- 1 | # `sqlite-jsonschema` NPM Package 2 | 3 | `sqlite-jsonschema` is distributed on `npm` for Node.js developers. To install on [supported platforms](#supported-platforms), simply run: 4 | 5 | ``` 6 | npm install sqlite-jsonschema 7 | ``` 8 | 9 | The `sqlite-jsonschema` package is meant to be used with Node SQLite clients like [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3) and [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3). For `better-sqlite3`, call [`.loadExtension()`](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#loadextensionpath-entrypoint---this) on your database object, passing in [`getLoadablePath()`](#getLoadablePath). 10 | 11 | ```js 12 | import Database from "better-sqlite3"; 13 | import * as sqlite_jsonschema from "sqlite-jsonschema"; 14 | 15 | const db = new Database(":memory:"); 16 | 17 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 18 | 19 | const version = db.prepare("select jsonschema_version()").pluck().get(); 20 | console.log(version); // "v0.2.0" 21 | ``` 22 | 23 | For `node-sqlite3`, call the similarly named [`.loadExtension()`](https://github.com/TryGhost/node-sqlite3/wiki/API#loadextensionpath--callback) method on your database object, and pass in [`getLoadablePath()`](#getLoadablePath). 24 | 25 | ```js 26 | import sqlite3 from "sqlite3"; 27 | import * as sqlite_jsonschema from "sqlite-jsonschema"; 28 | 29 | const db = new sqlite3.Database(":memory:"); 30 | 31 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 32 | 33 | db.get("select jsonschema_version()", (err, row) => { 34 | console.log(row); // {json_schema_version(): "v0.2.0"} 35 | }); 36 | ``` 37 | 38 | See [the full API Reference](#api-reference) for the Node API, and [`docs.md`](../../docs.md) for documentation on the `sqlite-jsonschema` SQL API. 39 | 40 | ## Supported Platforms 41 | 42 | Since the underlying `jsonschema0` SQLite extension is pre-compiled, the `sqlite-jsonschema` NPM package only works on a few "platforms" (operating systems + CPU architectures). These platforms include: 43 | 44 | - `darwin-x64` (MacOS x86_64) 45 | - `darwin-arm64` (MacOS M1 and M2 chips) 46 | - `win32-x64` (Windows x86_64) 47 | - `linux-x64` (Linux x86_64) 48 | 49 | To see which platform your machine is, check the [`process.arch`](https://nodejs.org/api/process.html#processarch) and [`process.platform`](https://nodejs.org/api/process.html#processplatform) values like so: 50 | 51 | ```bash 52 | $ node -e 'console.log([process.platform, process.arch])' 53 | [ 'darwin', 'x64' ] 54 | ``` 55 | 56 | When the `sqlite-jsonschema` NPM package is installed, the correct pre-compiled extension for your operating system and CPU architecture will be downloaded from the [optional dependencies](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#optionaldependencies), with platform-specific packages like `sqlite-jsonschema-darwin-x64`. This will be automatically, there's no need to directly install those packages. 57 | 58 | More platforms may be supported in the future. Consider [supporting my work](https://github.com/sponsors/asg017/) if you'd like to see more operating systems and CPU architectures supported in `sqlite-jsonschema`. 59 | 60 | ## API Reference 61 | 62 | # getLoadablePath [<>](https://github.com/asg017/sqlite-jsonschema/blob/main/npm/sqlite-jsonschema/src/index.js "Source") 63 | 64 | Returns the full path to where the `sqlite-jsonschema` _should_ be installed, based on the `sqlite-jsonschema`'s `package.json` optional dependencies and the host's operating system and architecture. 65 | 66 | This path can be directly passed into [`better-sqlite3`](https://github.com/WiseLibs/better-sqlite3)'s [`.loadExtension()`](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#loadextensionpath-entrypoint---this). 67 | 68 | ```js 69 | import Database from "better-sqlite3"; 70 | import * as sqlite_jsonschema from "sqlite-jsonschema"; 71 | 72 | const db = new Database(":memory:"); 73 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 74 | ``` 75 | 76 | It can also be used in [`node-sqlite3`](https://github.com/TryGhost/node-sqlite3)'s [`.loadExtension()`](https://github.com/TryGhost/node-sqlite3/wiki/API#loadextensionpath--callback). 77 | 78 | ```js 79 | import sqlite3 from "sqlite3"; 80 | import * as sqlite_jsonschema from "sqlite-jsonschema"; 81 | 82 | const db = new sqlite3.Database(":memory:"); 83 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 84 | ``` 85 | 86 | This function throws an `Error` in two different cases. The first case is when `sqlite-jsonschema` is installed and run on an [unsupported platform](#supported-platforms). The second case is when the platform-specific optional dependency is not installed. If you reach this, ensure you aren't using `--no-optional` flag, and [file an issue](https://github.com/asg017/sqlite-jsonschema/issues/new) if you are stuck. 87 | 88 | The `db.loadExtension()` function may also throw an Error if the compiled extension is incompatible with your SQLite connection for any reason, including missing system packages, outdated glib versions, or other misconfigurations. If you reach this, please [file an issue](https://github.com/asg017/sqlite-jsonschema/issues/new). 89 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "sqlite-jsonschema", 4 | "version": "0.2.3", 5 | "description": "", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/asg017/sqlite-jsonschema.git", 9 | "directory": "npm/sqlite-jsonschema" 10 | }, 11 | "author": "Alex Garcia ", 12 | "license": "(MIT OR Apache-2.0)", 13 | "main": "src/index.js", 14 | "type": "module", 15 | "scripts": { 16 | "test": "node test.js" 17 | }, 18 | "files": [ 19 | "*.dylib", 20 | "*.so", 21 | "*.dll" 22 | ], 23 | "optionalDependencies": { 24 | "sqlite-jsonschema-darwin-arm64": "0.2.3", 25 | "sqlite-jsonschema-darwin-x64": "0.2.3", 26 | "sqlite-jsonschema-linux-x64": "0.2.3", 27 | "sqlite-jsonschema-windows-x64": "0.2.3" 28 | }, 29 | "devDependencies": { 30 | "better-sqlite3": "^8.1.0", 31 | "sqlite3": "^5.1.4" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema/package.json.tmpl: -------------------------------------------------------------------------------- 1 | { 2 | "//": "Autogenerated by the npm_generate_platform_packages.sh script, do not edit by hand", 3 | "name": "${PACKAGE_NAME_BASE}", 4 | "version": "${VERSION}", 5 | "description": "", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/asg017/${PACKAGE_NAME_BASE}.git", 9 | "directory": "npm/${PACKAGE_NAME_BASE}" 10 | }, 11 | "author": "Alex Garcia ", 12 | "license": "(MIT OR Apache-2.0)", 13 | "main": "src/index.js", 14 | "type": "module", 15 | "scripts": { 16 | "test": "node test.js" 17 | }, 18 | "files": [ 19 | "*.dylib", 20 | "*.so", 21 | "*.dll" 22 | ], 23 | "optionalDependencies": { 24 | "sqlite-jsonschema-darwin-arm64": "${VERSION}", 25 | "sqlite-jsonschema-darwin-x64": "${VERSION}", 26 | "sqlite-jsonschema-linux-x64": "${VERSION}", 27 | "sqlite-jsonschema-windows-x64": "${VERSION}" 28 | }, 29 | "devDependencies": { 30 | "better-sqlite3": "^8.1.0", 31 | "sqlite3": "^5.1.4" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema/src/index.js: -------------------------------------------------------------------------------- 1 | import { join } from "node:path"; 2 | import { fileURLToPath } from "node:url"; 3 | import { arch, platform } from "node:process"; 4 | import { statSync } from "node:fs"; 5 | 6 | const supportedPlatforms = [ 7 | ["darwin", "x64"], 8 | ["darwin", "arm64"], 9 | ["win32", "x64"], 10 | ["linux", "x64"], 11 | ]; 12 | 13 | function validPlatform(platform, arch) { 14 | return ( 15 | supportedPlatforms.find(([p, a]) => platform == p && arch === a) !== null 16 | ); 17 | } 18 | function extensionSuffix(platform) { 19 | if (platform === "win32") return "dll"; 20 | if (platform === "darwin") return "dylib"; 21 | return "so"; 22 | } 23 | function platformPackageName(platform, arch) { 24 | const os = platform === "win32" ? "windows" : platform; 25 | return `sqlite-jsonschema-${os}-${arch}`; 26 | } 27 | 28 | export function getLoadablePath() { 29 | if (!validPlatform(platform, arch)) { 30 | throw new Error( 31 | `Unsupported platform for sqlite-jsonschema, on a ${platform}-${arch} machine, but not in supported platforms (${supportedPlatforms 32 | .map(([p, a]) => `${p}-${a}`) 33 | .join( 34 | "," 35 | )}). Consult the sqlite-jsonschema NPM package README for details. ` 36 | ); 37 | } 38 | const packageName = platformPackageName(platform, arch); 39 | const loadablePath = join( 40 | fileURLToPath(new URL(".", import.meta.url)), 41 | "..", 42 | "..", 43 | packageName, 44 | "lib", 45 | `jsonschema0.${extensionSuffix(platform)}` 46 | ); 47 | if (!statSync(loadablePath, { throwIfNoEntry: false })) { 48 | throw new Error( 49 | `Loadble extension for sqlite-jsonschema not found. Was the ${packageName} package installed? Avoid using the --no-optional flag, as the optional dependencies for sqlite-jsonschema are required.` 50 | ); 51 | } 52 | 53 | return loadablePath; 54 | } 55 | -------------------------------------------------------------------------------- /npm/sqlite-jsonschema/test.js: -------------------------------------------------------------------------------- 1 | import test from "node:test"; 2 | import * as assert from "node:assert"; 3 | 4 | import { getLoadablePath } from "./src/index.js"; 5 | import { basename, extname, isAbsolute } from "node:path"; 6 | 7 | import Database from "better-sqlite3"; 8 | import sqlite3 from "sqlite3"; 9 | 10 | test("getLoadblePath()", (t) => { 11 | const loadablePath = getLoadablePath(); 12 | assert.strictEqual(isAbsolute(loadablePath), true); 13 | assert.strictEqual( 14 | basename(loadablePath, extname(loadablePath)), 15 | "jsonschema0" 16 | ); 17 | }); 18 | 19 | test("better-sqlite3", (t) => { 20 | const db = new Database(":memory:"); 21 | db.loadExtension(getLoadablePath()); 22 | const version = db.prepare("select jsonschema_version()").pluck().get(); 23 | assert.strictEqual(version[0], "v"); 24 | }); 25 | 26 | test("sqlite3", async (t) => { 27 | const db = new sqlite3.Database(":memory:"); 28 | db.loadExtension(getLoadablePath()); 29 | let version = await new Promise((resolve, reject) => { 30 | db.get("select jsonschema_version()", (err, row) => { 31 | if (err) return reject(err); 32 | resolve(row["jsonschema_version()"]); 33 | }); 34 | }); 35 | assert.strictEqual(version[0], "v"); 36 | }); 37 | -------------------------------------------------------------------------------- /python/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # `sqlite-jsonschema` Python Packages 2 | 3 | The `sqlite-jsonschema` project offers two python packages for easy distribution. They are: 4 | 5 | 1. The [`sqlite-jsonschema` Python package](https://pypi.org/project/sqlite-jsonschema/), source in [`sqlite_jsonschema/`](./sqlite_jsonschema/README.md) 6 | 2. The [`datasette-sqlite-jsonschema` Python package](https://pypi.org/project/sqlite-jsonschema/), a [Datasette](https://datasette.io/) plugin,which is a light wrapper around the `sqlite-jsonschema` package, source in [`datasette_sqlite_jsonschema/`](./datasette_sqlite_jsonschema/README.md) 7 | -------------------------------------------------------------------------------- /python/datasette_sqlite_jsonschema/README.md: -------------------------------------------------------------------------------- 1 | # The `datasette-sqlite-jsonschema` Datasette Plugin 2 | 3 | `datasette-sqlite-jsonschema` is a [Datasette plugin](https://docs.datasette.io/en/stable/plugins.html) that loads the [`sqlite-jsonschema`](https://github.com/asg017/sqlite-jsonschema) extension in Datasette instances, allowing you to generate and work with [TODO](https://github.com/jsonschema/spec) in SQL. 4 | 5 | ``` 6 | datasette install datasette-sqlite-jsonschema 7 | ``` 8 | 9 | See [`docs.md`](../../docs.md) for a full API reference for the jsonschema SQL functions. 10 | 11 | Alternatively, when publishing Datasette instances, you can use the `--install` option to install the plugin. 12 | 13 | ``` 14 | datasette publish cloudrun data.db --service=my-service --install=datasette-sqlite-jsonschema 15 | 16 | ``` 17 | -------------------------------------------------------------------------------- /python/datasette_sqlite_jsonschema/datasette_sqlite_jsonschema/__init__.py: -------------------------------------------------------------------------------- 1 | from datasette import hookimpl 2 | import sqlite_jsonschema 3 | 4 | from datasette_sqlite_jsonschema.version import __version_info__, __version__ 5 | 6 | @hookimpl 7 | def prepare_connection(conn): 8 | conn.enable_load_extension(True) 9 | sqlite_jsonschema.load(conn) 10 | conn.enable_load_extension(False) -------------------------------------------------------------------------------- /python/datasette_sqlite_jsonschema/datasette_sqlite_jsonschema/version.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.2.3" 2 | __version_info__ = tuple(__version__.split(".")) 3 | -------------------------------------------------------------------------------- /python/datasette_sqlite_jsonschema/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | version = {} 4 | with open("datasette_sqlite_jsonschema/version.py") as fp: 5 | exec(fp.read(), version) 6 | 7 | VERSION = version['__version__'] 8 | 9 | setup( 10 | name="datasette-sqlite-jsonschema", 11 | description="", 12 | long_description="", 13 | long_description_content_type="text/markdown", 14 | author="Alex Garcia", 15 | url="https://github.com/asg017/sqlite-jsonschema", 16 | project_urls={ 17 | "Issues": "https://github.com/asg017/sqlite-jsonschema/issues", 18 | "CI": "https://github.com/asg017/sqlite-jsonschema/actions", 19 | "Changelog": "https://github.com/asg017/sqlite-jsonschema/releases", 20 | }, 21 | license="MIT License, Apache License, Version 2.0", 22 | version=VERSION, 23 | packages=["datasette_sqlite_jsonschema"], 24 | entry_points={"datasette": ["sqlite_jsonschema = datasette_sqlite_jsonschema"]}, 25 | install_requires=["datasette", "sqlite-jsonschema"], 26 | extras_require={"test": ["pytest"]}, 27 | python_requires=">=3.7", 28 | ) -------------------------------------------------------------------------------- /python/datasette_sqlite_jsonschema/tests/test_sqlite_jsonschema.py: -------------------------------------------------------------------------------- 1 | from datasette.app import Datasette 2 | import pytest 3 | 4 | 5 | @pytest.mark.asyncio 6 | async def test_plugin_is_installed(): 7 | datasette = Datasette(memory=True) 8 | response = await datasette.client.get("/-/plugins.json") 9 | assert response.status_code == 200 10 | installed_plugins = {p["name"] for p in response.json()} 11 | assert "datasette-sqlite-jsonschema" in installed_plugins 12 | 13 | @pytest.mark.asyncio 14 | async def test_sqlite_jsonschema_functions(): 15 | datasette = Datasette(memory=True) 16 | response = await datasette.client.get("/_memory.json?sql=select+jsonschema_version(),jsonschema()") 17 | assert response.status_code == 200 18 | jsonschema_version, jsonschema = response.json()["rows"][0] 19 | assert jsonschema_version[0] == "v" 20 | assert len(jsonschema) == 26 -------------------------------------------------------------------------------- /python/sqlite_jsonschema/README.md: -------------------------------------------------------------------------------- 1 | # The `sqlite-jsonschema` Python package 2 | 3 | `sqlite-jsonschema` is also distributed on PyPi as a Python package, for use in Python applications. It works well with the builtin [`sqlite3`](https://docs.python.org/3/library/sqlite3.html) Python module. 4 | 5 | ``` 6 | pip install sqlite-jsonschema 7 | ``` 8 | 9 | ## Usage 10 | 11 | The `sqlite-jsonschema` python package exports two functions: `loadable_path()`, which returns the full path to the loadable extension, and `load(conn)`, which loads the `sqlite-jsonschema` extension into the given [sqlite3 Connection object](https://docs.python.org/3/library/sqlite3.html#connection-objects). 12 | 13 | ```python 14 | import sqlite_jsonschema 15 | print(sqlite_jsonschema.loadable_path()) 16 | # '/.../venv/lib/python3.9/site-packages/sqlite_jsonschema/jsonschema0' 17 | 18 | import sqlite3 19 | conn = sqlite3.connect(':memory:') 20 | sqlite_jsonschema.load(conn) 21 | conn.execute('select jsonschema_version(), jsonschema()').fetchone() 22 | # ('v0.1.0', '01gr7gwc5aq22ycea6j8kxq4s9') 23 | ``` 24 | 25 | See [the full API Reference](#api-reference) for the Python API, and [`docs.md`](../../docs.md) for documentation on the `sqlite-jsonschema` SQL API. 26 | 27 | See [`datasette-sqlite-jsonschema`](../datasette_sqlite_jsonschema/) for a Datasette plugin that is a light wrapper around the `sqlite-jsonschema` Python package. 28 | 29 | ## Compatibility 30 | 31 | Currently the `sqlite-jsonschema` Python package is only distributed on PyPi as pre-build wheels, it's not possible to install from the source distribution. This is because the underlying `sqlite-jsonschema` extension requires a lot of build dependencies like `make`, `cc`, and `cargo`. 32 | 33 | If you get a `unsupported platform` error when pip installing `sqlite-jsonschema`, you'll have to build the `sqlite-jsonschema` manually and load in the dynamic library manually. 34 | 35 | ## API Reference 36 | 37 |

loadable_path()

38 | 39 | Returns the full path to the locally-install `sqlite-jsonschema` extension, without the filename. 40 | 41 | This can be directly passed to [`sqlite3.Connection.load_extension()`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.load_extension), but the [`sqlite_jsonschema.load()`](#load) function is preferred. 42 | 43 | ```python 44 | import sqlite_jsonschema 45 | print(sqlite_jsonschema.loadable_path()) 46 | # '/.../venv/lib/python3.9/site-packages/sqlite_jsonschema/jsonschema0' 47 | ``` 48 | 49 | > Note: this extension path doesn't include the file extension (`.dylib`, `.so`, `.dll`). This is because [SQLite will infer the correct extension](https://www.sqlite.org/loadext.html#loading_an_extension). 50 | 51 |

load(connection)

52 | 53 | Loads the `sqlite-jsonschema` extension on the given [`sqlite3.Connection`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection) object, calling [`Connection.load_extension()`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.load_extension). 54 | 55 | ```python 56 | import sqlite_jsonschema 57 | import sqlite3 58 | conn = sqlite3.connect(':memory:') 59 | 60 | conn.enable_load_extension(True) 61 | sqlite_jsonschema.load(conn) 62 | conn.enable_load_extension(False) 63 | 64 | conn.execute('select jsonschema_version(), jsonschema()').fetchone() 65 | # ('v0.1.0', '01gr7gwc5aq22ycea6j8kxq4s9') 66 | ``` 67 | -------------------------------------------------------------------------------- /python/sqlite_jsonschema/noop.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asg017/sqlite-jsonschema/fadd55ddc28537f5f8769205e2c0798dfb854b79/python/sqlite_jsonschema/noop.c -------------------------------------------------------------------------------- /python/sqlite_jsonschema/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, Extension 2 | import os 3 | import platform 4 | 5 | version = {} 6 | with open("sqlite_jsonschema/version.py") as fp: 7 | exec(fp.read(), version) 8 | 9 | VERSION = version['__version__'] 10 | 11 | 12 | system = platform.system() 13 | machine = platform.machine() 14 | 15 | print(system, machine) 16 | 17 | if system == 'Darwin': 18 | if machine not in ['x86_64', 'arm64']: 19 | raise Exception("unsupported platform") 20 | elif system == 'Linux': 21 | if machine not in ['x86_64']: 22 | raise Exception("unsupported platform") 23 | elif system == 'Windows': 24 | # TODO only 64 bit I think 25 | pass 26 | else: 27 | raise Exception("unsupported platform") 28 | 29 | setup( 30 | name="sqlite-jsonschema", 31 | description="", 32 | long_description="", 33 | long_description_content_type="text/markdown", 34 | author="Alex Garcia", 35 | url="https://github.com/asg017/sqlite-jsonschema", 36 | project_urls={ 37 | "Issues": "https://github.com/asg017/sqlite-jsonschema/issues", 38 | "CI": "https://github.com/asg017/sqlite-jsonschema/actions", 39 | "Changelog": "https://github.com/asg017/sqlite-jsonschema/releases", 40 | }, 41 | license="MIT License, Apache License, Version 2.0", 42 | version=VERSION, 43 | packages=["sqlite_jsonschema"], 44 | package_data={"sqlite_jsonschema": ['*.so', '*.dylib', '*.dll']}, 45 | install_requires=[], 46 | # Adding an Extension makes `pip wheel` believe that this isn't a 47 | # pure-python package. The noop.c was added since the windows build 48 | # didn't seem to respect optional=True 49 | ext_modules=[Extension("noop", ["noop.c"], optional=True)], 50 | extras_require={"test": ["pytest"]}, 51 | python_requires=">=3.7", 52 | ) -------------------------------------------------------------------------------- /python/sqlite_jsonschema/sqlite_jsonschema/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sqlite3 3 | 4 | from sqlite_jsonschema.version import __version_info__, __version__ 5 | 6 | def loadable_path(): 7 | loadable_path = os.path.join(os.path.dirname(__file__), "jsonschema0") 8 | return os.path.normpath(loadable_path) 9 | 10 | def load(conn: sqlite3.Connection) -> None: 11 | conn.load_extension(loadable_path()) 12 | -------------------------------------------------------------------------------- /python/sqlite_jsonschema/sqlite_jsonschema/version.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.2.3" 2 | __version_info__ = tuple(__version__.split(".")) 3 | -------------------------------------------------------------------------------- /scripts/deno_generate_package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | export PACKAGE_NAME="sqlite-jsonschema" 6 | export EXTENSION_NAME="jsonschema0" 7 | export VERSION=$(cat VERSION) 8 | 9 | envsubst < deno/deno.json.tmpl > deno/deno.json 10 | echo "✅ generated deno/deno.json" 11 | 12 | envsubst < deno/README.md.tmpl > deno/README.md 13 | echo "✅ generated deno/README.md" 14 | -------------------------------------------------------------------------------- /scripts/npm_generate_platform_packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | export PACKAGE_NAME_BASE="sqlite-jsonschema" 6 | export EXTENSION_NAME="jsonschema0" 7 | export VERSION=$(cat VERSION) 8 | 9 | generate () { 10 | export PLATFORM_OS=$1 11 | export PLATFORM_ARCH=$2 12 | export PACKAGE_NAME=$PACKAGE_NAME_BASE-$PLATFORM_OS-$PLATFORM_ARCH 13 | 14 | if [ "$PLATFORM_OS" == "windows" ]; then 15 | export EXTENSION_SUFFIX="dll" 16 | elif [ "$PLATFORM_OS" == "darwin" ]; then 17 | export EXTENSION_SUFFIX="dylib" 18 | else 19 | export EXTENSION_SUFFIX="so" 20 | fi 21 | 22 | 23 | mkdir -p npm/$PACKAGE_NAME/lib 24 | 25 | envsubst < npm/platform-package.package.json.tmpl > npm/$PACKAGE_NAME/package.json 26 | envsubst < npm/platform-package.README.md.tmpl > npm/$PACKAGE_NAME/README.md 27 | 28 | touch npm/$PACKAGE_NAME/lib/.gitkeep 29 | 30 | echo "✅ generated npm/$PACKAGE_NAME" 31 | } 32 | 33 | envsubst < npm/$PACKAGE_NAME_BASE/package.json.tmpl > npm/$PACKAGE_NAME_BASE/package.json 34 | echo "✅ generated npm/$PACKAGE_NAME_BASE" 35 | 36 | generate darwin x64 37 | generate darwin arm64 38 | generate linux x64 39 | generate windows x64 -------------------------------------------------------------------------------- /scripts/publish_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail xtrace 4 | 5 | if [[ -n $(git status --porcelain | grep -v VERSION) ]]; then 6 | echo "❌ There are other un-staged changes to the repository besides VERSION" 7 | exit 1 8 | fi 9 | 10 | VERSION="$(cat VERSION)" 11 | 12 | echo "Publishing version v$VERSION..." 13 | 14 | make version 15 | git add --all 16 | git commit -m "v$VERSION" 17 | git tag v$VERSION 18 | git push origin main v$VERSION 19 | 20 | if grep -qE "alpha|beta" VERSION; then 21 | gh release create v$VERSION --title=v$VERSION --prerelease --notes="" 22 | else 23 | gh release create v$VERSION --title=v$VERSION 24 | fi 25 | 26 | 27 | echo "✅ Published! version v$VERSION" 28 | -------------------------------------------------------------------------------- /scripts/site_generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | 4 | export RESULT_VERSION=$(sqlite3 :memory: '.mode quote' '.load ./dist/debug/jsonschema0' 'select jsonschema_version()') 5 | export RESULT_DEBUG=$( sqlite3 :memory: '.mode quote' '.load ./dist/debug/jsonschema0' 'select jsonschema_debug()') 6 | 7 | envsubst < site/reference.md.tmpl > site/reference.md 8 | -------------------------------------------------------------------------------- /site/_config.ts: -------------------------------------------------------------------------------- 1 | import lume from "lume/mod.ts"; 2 | import codeHighlight from "lume/plugins/code_highlight.ts"; 3 | import javascript from "https://unpkg.com/@highlightjs/cdn-assets@11.6.0/es/languages/javascript.min.js"; 4 | import python from "https://unpkg.com/@highlightjs/cdn-assets@11.6.0/es/languages/python.min.js"; 5 | 6 | import anchor from "npm:markdown-it-anchor"; 7 | import sql from "./_sql.ts"; 8 | const site = lume( 9 | { 10 | prettyUrls: false, 11 | location: new URL("https://alexgarcia.xyz/sqlite-jsonschema"), 12 | }, 13 | { 14 | markdown: { 15 | plugins: [[anchor, { level: 2 }]], 16 | keepDefaultPlugins: true, 17 | }, 18 | } 19 | ); 20 | 21 | site.data("VERSION", "v" + Deno.readTextFileSync("../VERSION")); 22 | site.data("project", "sqlite-jsonschema"); 23 | const SOURCE_ID = new TextDecoder().decode( 24 | await Deno.run({ 25 | cmd: ["git", "rev-parse", "HEAD"], 26 | stdout: "piped", 27 | }).output() 28 | ); 29 | 30 | site.data("SOURCE_ID", SOURCE_ID); 31 | site.data("SOURCE_ID_SHORT", SOURCE_ID.substring(0, 7)); 32 | site.data("BUILD_DATE", new Date().toISOString()); 33 | 34 | site.use( 35 | codeHighlight({ 36 | languages: { 37 | sql, 38 | javascript, 39 | python, 40 | }, 41 | }) 42 | ); 43 | 44 | site.copy("static/pico.min.css"); 45 | site.copy("static/script.js"); 46 | site.copy("static/style.css"); 47 | site.copy("static/github-mark.svg"); 48 | site.copy("static/github-mark-white.svg"); 49 | 50 | export default site; 51 | -------------------------------------------------------------------------------- /site/_data.yaml: -------------------------------------------------------------------------------- 1 | layout: base.njk 2 | sidebar_menu: 3 | - title: Using with... 4 | id: usage 5 | nested: true 6 | - title: Examples 7 | id: example 8 | - title: API Reference 9 | id: reference 10 | -------------------------------------------------------------------------------- /site/_includes/base.njk: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | {{yo}} 11 | {% if title %} 12 | {{ title }} - {{ project }} 13 | {% else %} 14 | {{ project }} - A SQLite extension for JSON Schema Validation 15 | {% endif %} 16 | 17 | 18 | 19 | 23 | 24 | 25 |
26 |
27 | 35 | 36 | 41 | 42 |
43 |
44 | 45 |
46 | {% include "navbar.njk" %} 47 |
48 | {{ content | safe }} 49 |
50 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /site/_includes/navbar.njk: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /site/_sql.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Language: SQL 3 | Website: https://en.wikipedia.org/wiki/SQL 4 | Category: common, database 5 | */ 6 | 7 | /* 8 | 9 | Goals: 10 | 11 | SQL is intended to highlight basic/common SQL keywords and expressions 12 | 13 | - If pretty much every single SQL server includes supports, then it's a canidate. 14 | - It is NOT intended to include tons of vendor specific keywords (Oracle, MySQL, 15 | PostgreSQL) although the list of data types is purposely a bit more expansive. 16 | - For more specific SQL grammars please see: 17 | - PostgreSQL and PL/pgSQL - core 18 | - T-SQL - https://github.com/highlightjs/highlightjs-tsql 19 | - sql_more (core) 20 | 21 | */ 22 | 23 | export default function (hljs) { 24 | const regex = hljs.regex; 25 | const COMMENT_MODE = hljs.COMMENT("--", "$"); 26 | const STRING = { 27 | className: "string", 28 | variants: [ 29 | { 30 | begin: /'/, 31 | end: /'/, 32 | contains: [{ begin: /''/ }], 33 | }, 34 | // blob syntax 35 | { 36 | begin: /X'/, 37 | end: /'/, 38 | contains: [{ begin: /''/ }], 39 | }, 40 | ], 41 | }; 42 | const QUOTED_IDENTIFIER = { 43 | begin: /"/, 44 | end: /"/, 45 | contains: [{ begin: /""/ }], 46 | }; 47 | 48 | const LITERALS = [ 49 | "true", 50 | "false", 51 | // Not sure it's correct to call NULL literal, and clauses like IS [NOT] NULL look strange that way. 52 | // "null", 53 | "unknown", // TODO remove? 54 | ]; 55 | 56 | const MULTI_WORD_TYPES = [ 57 | "double precision", 58 | "large object", 59 | "with timezone", 60 | "without timezone", 61 | ]; 62 | 63 | const TYPES = [ 64 | "bigint", 65 | "binary", 66 | "blob", 67 | "boolean", 68 | "char", 69 | "character", 70 | "clob", 71 | "date", 72 | "dec", 73 | "decfloat", 74 | "decimal", 75 | "float", 76 | "int", 77 | "integer", 78 | "interval", 79 | "nchar", 80 | "nclob", 81 | "national", 82 | "numeric", 83 | "real", 84 | "row", 85 | "smallint", 86 | "text", // NEW 87 | "time", 88 | "timestamp", 89 | "varchar", 90 | "varying", // modifier (character varying) 91 | "varbinary", 92 | "json", // NEW 93 | ]; 94 | 95 | const NON_RESERVED_WORDS = [ 96 | "add", 97 | "asc", 98 | "collation", 99 | "desc", 100 | "final", 101 | "first", 102 | "last", 103 | "view", 104 | ]; 105 | 106 | const RESERVED_WORDS = [ 107 | // https://www.sqlite.org/lang_keywords.html 108 | // NOT included: KEY 109 | ...`ABORT 110 | ACTION 111 | ADD 112 | AFTER 113 | ALL 114 | ALTER 115 | ALWAYS 116 | ANALYZE 117 | AND 118 | AS 119 | ASC 120 | ATTACH 121 | AUTOINCREMENT 122 | BEFORE 123 | BEGIN 124 | BETWEEN 125 | BY 126 | CASCADE 127 | CASE 128 | CAST 129 | CHECK 130 | COLLATE 131 | COLUMN 132 | COMMIT 133 | CONFLICT 134 | CONSTRAINT 135 | CREATE 136 | CROSS 137 | CURRENT 138 | CURRENT_DATE 139 | CURRENT_TIME 140 | CURRENT_TIMESTAMP 141 | DATABASE 142 | DEFAULT 143 | DEFERRABLE 144 | DEFERRED 145 | DELETE 146 | DESC 147 | DETACH 148 | DISTINCT 149 | DO 150 | DROP 151 | EACH 152 | ELSE 153 | END 154 | ESCAPE 155 | EXCEPT 156 | EXCLUDE 157 | EXCLUSIVE 158 | EXISTS 159 | EXPLAIN 160 | FAIL 161 | FILTER 162 | FIRST 163 | FOLLOWING 164 | FOR 165 | FOREIGN 166 | FROM 167 | FULL 168 | GENERATED 169 | GLOB 170 | GROUP 171 | GROUPS 172 | HAVING 173 | IF 174 | IGNORE 175 | IMMEDIATE 176 | IN 177 | INDEX 178 | INDEXED 179 | INITIALLY 180 | INNER 181 | INSERT 182 | INSTEAD 183 | INTERSECT 184 | INTO 185 | IS 186 | ISNULL 187 | JOIN 188 | LAST 189 | LEFT 190 | LIKE 191 | LIMIT 192 | MATCH 193 | MATERIALIZED 194 | NATURAL 195 | NO 196 | NOT 197 | NOTHING 198 | NOTNULL 199 | NULL 200 | NULLS 201 | OF 202 | OFFSET 203 | ON 204 | OR 205 | ORDER 206 | OTHERS 207 | OUTER 208 | OVER 209 | PARTITION 210 | PLAN 211 | PRAGMA 212 | PRECEDING 213 | PRIMARY 214 | QUERY 215 | RAISE 216 | RANGE 217 | RECURSIVE 218 | REFERENCES 219 | REGEXP 220 | x->> 221 | REINDEX 222 | RELEASE 223 | RENAME 224 | REPLACE 225 | RESTRICT 226 | RETURNING 227 | RIGHT 228 | ROLLBACK 229 | ROW 230 | ROWS 231 | SAVEPOINT 232 | SELECT 233 | SET 234 | TABLE 235 | TEMP 236 | TEMPORARY 237 | THEN 238 | TIES 239 | TO 240 | TRANSACTION 241 | TRIGGER 242 | UNBOUNDED 243 | UNION 244 | UNIQUE 245 | UPDATE 246 | USING 247 | VACUUM 248 | VALUES 249 | VIEW 250 | VIRTUAL 251 | WHEN 252 | WHERE 253 | WINDOW 254 | WITH 255 | WITHOUT 256 | \.load 257 | \.bail`.split("\n"), 258 | ]; 259 | 260 | // these are reserved words we have identified to be functions 261 | // and should only be highlighted in a dispatch-like context 262 | // ie, array_agg(...), etc. 263 | const RESERVED_FUNCTIONS = [ 264 | // select name from pragma_function_list where builtin group by 1 order by 1; 265 | ...`-> 266 | ->> 267 | x->> 268 | abs 269 | acos 270 | acosh 271 | asin 272 | asinh 273 | atan 274 | atan2 275 | atanh 276 | avg 277 | ceil 278 | ceiling 279 | changes 280 | char 281 | coalesce 282 | cos 283 | cosh 284 | count 285 | cume_dist 286 | current_date 287 | current_time 288 | current_timestamp 289 | date 290 | datetime 291 | degrees 292 | dense_rank 293 | exp 294 | first_value 295 | floor 296 | format 297 | glob 298 | group_concat 299 | hex 300 | ifnull 301 | iif 302 | instr 303 | json 304 | json_array 305 | json_array_length 306 | json_extract 307 | json_group_array 308 | json_group_object 309 | json_insert 310 | json_object 311 | json_patch 312 | json_quote 313 | json_remove 314 | json_replace 315 | json_set 316 | json_type 317 | json_valid 318 | julianday 319 | lag 320 | last_insert_rowid 321 | last_value 322 | lead 323 | length 324 | like 325 | likelihood 326 | likely 327 | ln 328 | load_extension 329 | log 330 | log10 331 | log2 332 | lower 333 | ltrim 334 | max 335 | min 336 | mod 337 | nth_value 338 | ntile 339 | nullif 340 | percent_rank 341 | pi 342 | pow 343 | power 344 | printf 345 | quote 346 | radians 347 | random 348 | randomblob 349 | rank 350 | replace 351 | round 352 | row_number 353 | rtrim 354 | sign 355 | sin 356 | sinh 357 | sqlite_compileoption_get 358 | sqlite_compileoption_used 359 | sqlite_log 360 | sqlite_offset 361 | sqlite_source_id 362 | sqlite_version 363 | sqrt 364 | strftime 365 | substr 366 | substring 367 | subtype 368 | sum 369 | tan 370 | tanh 371 | time 372 | total 373 | total_changes 374 | trim 375 | trunc 376 | typeof 377 | unicode 378 | unixepoch 379 | unknown 380 | unlikely 381 | upper 382 | zeroblob`.split("\n"), 383 | // select * from pragma_module_list order by 1; 384 | ...`bytecode 385 | completion 386 | dbstat 387 | fsdir 388 | fts3 389 | fts3tokenize 390 | fts4 391 | fts4aux 392 | generate_series 393 | json_each 394 | json_tree 395 | pragma_function_list 396 | pragma_module_list 397 | pragma_table_info 398 | rtree 399 | rtree_i32 400 | sqlite_dbdata 401 | sqlite_dbpage 402 | sqlite_dbptr 403 | sqlite_stmt 404 | tables_used 405 | zipfile`.split("\n"), 406 | // https://www.sqlite.org/schematab.html 407 | ...`sqlite_schema sqlite_master sqlite_temp_schema sqlite_temp_master`.split( 408 | " " 409 | ), 410 | ]; 411 | 412 | // these functions can 413 | const POSSIBLE_WITHOUT_PARENS = [ 414 | ...`CURRENT 415 | CURRENT_DATE 416 | CURRENT_TIME 417 | CURRENT_TIMESTAMP`.split("\n"), 418 | //`.load`.split(" "), 419 | ]; 420 | 421 | // those exist to boost relevance making these very 422 | // "SQL like" keyword combos worth +1 extra relevance 423 | const COMBOS = [ 424 | "create table", 425 | "create virtual table", // NEW 426 | "without rowid", // NEW 427 | "delete from", // NEW 428 | "insert into", 429 | "primary key", 430 | "foreign key", 431 | "not null", 432 | "alter table", 433 | "add constraint", 434 | "grouping sets", 435 | "on overflow", 436 | "character set", 437 | "respect nulls", 438 | "ignore nulls", 439 | "nulls first", 440 | "nulls last", 441 | "depth first", 442 | "breadth first", 443 | ]; 444 | 445 | const FUNCTIONS = RESERVED_FUNCTIONS; 446 | 447 | const KEYWORDS = [...RESERVED_WORDS, ...NON_RESERVED_WORDS].filter( 448 | (keyword) => { 449 | return !RESERVED_FUNCTIONS.includes(keyword); 450 | } 451 | ); 452 | 453 | const VARIABLE = { 454 | className: "variable", 455 | begin: 456 | // @xyz 457 | // :xyz 458 | // ? or ?NNN 459 | // $xyz or $xyz::(anything) 460 | /(@[a-z0-9]+)|(:[a-z0-9]+)|(\$[a-z0-9]+(::\([a-z0-9]+\))?)|(\?([0-9]*))/, 461 | }; 462 | 463 | const OPERATOR = { 464 | className: "operator", 465 | // makes sure that the "->" and "->>" builtin functions aren't caught in this 466 | begin: /(?!->>)(?!->)(?=[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?)/, 467 | relevance: 0, 468 | }; 469 | 470 | const FUNCTION_CALL = { 471 | begin: regex.concat(/\b/, regex.either(...FUNCTIONS), /\s*\(/), 472 | relevance: 0, 473 | keywords: { built_in: FUNCTIONS }, 474 | }; 475 | 476 | // keywords with less than 3 letters are reduced in relevancy 477 | function reduceRelevancy(list, { exceptions, when } = {}) { 478 | const qualifyFn = when; 479 | exceptions = exceptions || []; 480 | return list.map((item) => { 481 | if (item.match(/\|\d+$/) || exceptions.includes(item)) { 482 | return item; 483 | } else if (qualifyFn(item)) { 484 | return `${item}|0`; 485 | } else { 486 | return item; 487 | } 488 | }); 489 | } 490 | 491 | return { 492 | name: "SQL", 493 | case_insensitive: true, 494 | // does not include {} or HTML tags ` x.length < 3 }), 499 | literal: LITERALS, 500 | type: TYPES, 501 | built_in: POSSIBLE_WITHOUT_PARENS, 502 | }, 503 | contains: [ 504 | { 505 | className: "keyword", 506 | begin: /(primary key)|(foreign key)/i, 507 | }, 508 | { 509 | begin: regex.either(...COMBOS), 510 | relevance: 0, 511 | keywords: { 512 | $pattern: /[\w\.]+/, 513 | keyword: KEYWORDS.concat(COMBOS), 514 | literal: LITERALS, 515 | type: TYPES, 516 | }, 517 | }, 518 | { 519 | className: "type", 520 | begin: regex.either(...MULTI_WORD_TYPES), 521 | }, 522 | { 523 | className: "prompt", 524 | begin: /sqlite\> */, 525 | }, 526 | { 527 | className: "built_in", 528 | begin: /(->>)|(->)/, 529 | }, 530 | { 531 | className: "dotcommand", 532 | begin: regex.either( 533 | ...`archive 534 | auth 535 | backup 536 | bail 537 | binary 538 | cd 539 | changes 540 | check 541 | clone 542 | connection 543 | databases 544 | dbconfig 545 | dbinfo 546 | dump 547 | echo 548 | eqp 549 | excel 550 | exit 551 | expert 552 | explain 553 | filectrl 554 | fullschema 555 | header 556 | headers 557 | help 558 | import 559 | imposter 560 | indexes 561 | limit 562 | lint 563 | load 564 | log 565 | mode 566 | nonce 567 | nullvalue 568 | once 569 | open 570 | output 571 | parameter 572 | print 573 | progress 574 | prompt 575 | quit 576 | read 577 | recover 578 | restore 579 | save 580 | scanstats 581 | schema 582 | selftest 583 | separator 584 | sha3sum 585 | shell 586 | show 587 | stats 588 | system 589 | tables 590 | testcase 591 | testctrl 592 | timeout 593 | timer 594 | trace 595 | vfsinfo 596 | vfslist 597 | vfsname 598 | width` 599 | .split("\n") 600 | .map((d) => `\\.${d}`) 601 | ), 602 | }, 603 | FUNCTION_CALL, 604 | VARIABLE, 605 | STRING, 606 | QUOTED_IDENTIFIER, 607 | hljs.C_NUMBER_MODE, 608 | hljs.C_BLOCK_COMMENT_MODE, 609 | COMMENT_MODE, 610 | OPERATOR, 611 | ], 612 | }; 613 | } 614 | -------------------------------------------------------------------------------- /site/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "lume": "echo \"import 'lume/cli.ts'\" | deno run --unstable -A -", 4 | "build": "deno task lume", 5 | "serve": "deno task lume -s" 6 | }, 7 | "imports": { 8 | "lume/": "https://deno.land/x/lume@v1.15.3/" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /site/examples.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Examples 3 | order: 2 4 | --- 5 | 6 | # Examples 7 | -------------------------------------------------------------------------------- /site/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | project: sqlite-jsonschema 3 | --- 4 | 5 | # sqlite-jsonschema 6 | 7 | A SQLite extension for validating JSON objects with [JSON Schema](https://json-schema.org/). Based on [`sqlite-loadable-rs`](https://github.com/asg017/sqlite-loadable-rs) and the [`jsonschema` crate](https://crates.io/crates/jsonschema). 8 | 9 | Available on `pip` for Python, `npm` for Node.js, `deno.land/x` for Deno, and pre-compiled extensions on Github Releases. 10 | 11 | ## Usage 12 | 13 | TODO 14 | 15 | - [ ] ".header on" color on/off, "mode box" color box/quote/etc 16 | 17 | ```sql 18 | select regex_find( 19 | '[0-9]{3}-[0-9]{3}-[0-9]{4}', 20 | 'phone: 111-222-3333' 21 | ); 22 | -- '111-222-3333' 23 | 24 | select rowid, * 25 | from regex_find_all( 26 | '\b\w{13}\b', 27 | 'Retroactively relinquishing remunerations is reprehensible.' 28 | ); 29 | /* 30 | ┌───────┬───────┬─────┬───────────────┐ 31 | │ rowid │ start │ end │ match │ 32 | ├───────┼───────┼─────┼───────────────┤ 33 | │ 0 │ 0 │ 13 │ Retroactively │ 34 | │ 1 │ 14 │ 27 │ relinquishing │ 35 | │ 2 │ 28 │ 41 │ remunerations │ 36 | │ 3 │ 45 │ 58 │ reprehensible │ 37 | └───────┴───────┴─────┴───────────────┘ 38 | */ 39 | ``` 40 | 41 | ```sql 42 | .load ./jsonschema 43 | .mode box 44 | .header on 45 | 46 | select 47 | value ->> '$.key.value', 48 | value -> '$.key.value', 49 | 1 - 2 << 5; 50 | 51 | create table students( 52 | id text primary key, 53 | district text, 54 | foreign key (district) references district(id), 55 | -- age in years 56 | age integer, 57 | -- full name, first and last 58 | name text 59 | ); 60 | 61 | /* 62 | much longer comment! 63 | */ 64 | select 65 | key, 66 | value 67 | from json_each( 68 | '[ 69 | {"name": "alex"}, 70 | {"name": "brian"} 71 | ]' 72 | ) 73 | where value like 'ale%' 74 | limit 50; 75 | 76 | 77 | with matches as ( 78 | select 79 | rowid, 80 | distance 81 | from vss_articles 82 | where vss_search( 83 | headline_embedding, 84 | ( 85 | select headline_embedding f 86 | rom articles 87 | where rowid = :id 88 | ) 89 | ) 90 | limit 20 91 | ) 92 | select 93 | articles.rowid, 94 | articles.headline, 95 | matches.distance 96 | from matches 97 | left join articles on articles.rowid = matches.rowid; 98 | ``` 99 | 100 | ```sql 101 | .load ./jsonschema0 102 | select jsonschema_matches( 103 | '{"maxLength": 5}', 104 | json_quote('alex') 105 | ); 106 | ``` 107 | 108 | Use with SQLite's [`CHECK` constraints](https://www.sqlite.org/lang_createtable.html#check_constraints) to validate JSON columns before inserting into a table. 109 | 110 | ```sql 111 | CREATE TABLE customer( 112 | cust_id INTEGER PRIMARY KEY, 113 | cust_name TEXT, 114 | cust_addr TEXT 115 | ); 116 | 117 | SELECT * FROM email WHERE email MATCH 'fts5'; 118 | 119 | attach database './yo.db' as yo; 120 | 121 | select @variable; 122 | 123 | -- TODO 124 | select :variable; 125 | select $variable, $var::(blaog); 126 | select ?, ?1; 127 | 128 | pragma table_info; 129 | 130 | select 131 | null, 132 | 'single', 133 | "double", 134 | 1234, 135 | -987, 136 | 0xdeadbeef, 137 | X'53514C697465'; 138 | ``` 139 | 140 | ```sql 141 | create virtual table xyz using vss0( 142 | headline_embedding(2048), 143 | ); 144 | 145 | select 146 | 1 + 2 - 4 >>, --x 147 | event ->> '$.table', 148 | event x->> '$.table', 149 | event.timestamp, 150 | event.result regexp '^abc$', 151 | name like '%yo%', 152 | datetime() as created_at, 153 | sqlite_compileoption_get(), 154 | x is not null, 155 | x is null, 156 | y is true, 157 | y is not false, 158 | y is false, 159 | json_object( 160 | 'a', json_array(1,2,3), 161 | 'b', json_object('name', 'alex'), 162 | 'c', json('{"": "pls"}'), 163 | 'd', json_valid('[]') 164 | ), 165 | from logs 166 | join json_each(logs.line) as event 167 | order by created_at asc 168 | limit 20; 169 | 170 | create view x as select 1, 2, 3 from b; 171 | 172 | create table students( 173 | id text, 174 | data json check ( 175 | jsonschema_matches( 176 | json(' 177 | { 178 | "type": "object", 179 | "properties": { 180 | "firstName": { 181 | "type": "string" 182 | }, 183 | "lastName": { 184 | "type": "string" 185 | }, 186 | "age": { 187 | "type": "integer", 188 | "minimum": 0 189 | } 190 | } 191 | } 192 | '), 193 | data 194 | ) 195 | ) 196 | ); 197 | 198 | insert into students(data) 199 | values ('{"firstName": "Alex", "lastName": "Garcia", "age": 100}'); 200 | -- ✓ 201 | 202 | 203 | insert into students(data) 204 | values ('{"firstName": "Alex", "lastName": "Garcia", "age": -1}'); 205 | -- Runtime error: CHECK constraint failed: jsonschema_matches 206 | 207 | ``` 208 | 209 | Find all the values in a column that don't match a JSON Schema. 210 | 211 | ```sql 212 | select 213 | rowid, 214 | jsonschema_matches( 215 | '{ 216 | "type": "array", 217 | "items": { 218 | "type": "number" 219 | } 220 | }', 221 | foo 222 | ) as valid 223 | from bar 224 | where not valid; 225 | ``` 226 | 227 | ## See also 228 | 229 | - [sqlite-xsv](https://github.com/asg017/sqlite-xsv), A SQLite extension for working with CSVs 230 | - [sqlite-loadable](https://github.com/asg017/sqlite-loadable-rs), A framework for writing SQLite extensions in Rust 231 | - [sqlite-http](https://github.com/asg017/sqlite-http), A SQLite extension for making HTTP requests 232 | -------------------------------------------------------------------------------- /site/reference.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: API Reference 3 | order: 1 4 | --- 5 | 6 | # API Reference 7 | 8 | A full reference to every function and module that `sqlite-jsonschema` offers. 9 | 10 | As a reminder, `sqlite-jsonschema` follows semver and is pre v1, so breaking changes are to be expected. 11 | 12 | ## SQL API 13 | 14 |

#jsonschema_matches(schema, document)

15 | 16 | Returns `1` if the given `document` matches the given `schema`, where `schema` is a valid JSON Schema. Returns `0` otherwise. 17 | 18 | ```sql 19 | select jsonschema_matches( 20 | '{"maxLength": 5}', 21 | json_quote('alex') 22 | ); 23 | 1 24 | 25 | select jsonschema_matches( 26 | '{"maxLength": 5}', 27 | json_quote('alexxx') 28 | ); 29 | 0 30 | ``` 31 | 32 |

#jsonschema_version()

33 | 34 | Returns the semver version string of the current version of `sqlite-jsonschema`. 35 | 36 | ```sql 37 | select jsonschema_version(); 38 | 'v0.2.1' 39 | ``` 40 | 41 |

#jsonschema_debug()

42 | 43 | Returns a debug string of various info about `sqlite-jsonschema`, including 44 | the version string, build date, and commit hash. 45 | 46 | ```sql 47 | select jsonschema_debug(); 48 | 'Version: v0.2.1 49 | Source: 52adccb319fb4f89f04d6ea696fedef3db198ed8 50 | ' 51 | ``` 52 | -------------------------------------------------------------------------------- /site/reference.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | title: API Reference 3 | order: 1 4 | --- 5 | 6 | # API Reference 7 | 8 | A full reference to every function and module that `sqlite-jsonschema` offers. 9 | 10 | As a reminder, `sqlite-jsonschema` follows semver and is pre v1, so breaking changes are to be expected. 11 | 12 | ## SQL API 13 | 14 |

#jsonschema_matches(schema, document)

15 | 16 | Returns `1` if the given `document` matches the given `schema`, where `schema` is a valid JSON Schema. Returns `0` otherwise. 17 | 18 | ```sql 19 | select jsonschema_matches( 20 | '{"maxLength": 5}', 21 | json_quote('alex') 22 | ); 23 | 1 24 | 25 | select jsonschema_matches( 26 | '{"maxLength": 5}', 27 | json_quote('alexxx') 28 | ); 29 | 0 30 | ``` 31 | 32 |

#jsonschema_version()

33 | 34 | Returns the semver version string of the current version of `sqlite-jsonschema`. 35 | 36 | ```sql 37 | select jsonschema_version(); 38 | ${RESULT_VERSION} 39 | ``` 40 | 41 |

#jsonschema_debug()

42 | 43 | Returns a debug string of various info about `sqlite-jsonschema`, including 44 | the version string, build date, and commit hash. 45 | 46 | ```sql 47 | select jsonschema_debug(); 48 | ${RESULT_DEBUG} 49 | ``` 50 | -------------------------------------------------------------------------------- /site/static/github-mark-white.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /site/static/github-mark.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /site/static/script.js: -------------------------------------------------------------------------------- 1 | Array.from(document.querySelectorAll(".hljs-built_in")).map((element) => { 2 | const name = element.textContent; 3 | element.addEventListener("mouseover", (e) => { 4 | console.log("over", name); 5 | }); 6 | element.addEventListener("mouseleave", (e) => { 7 | console.log("leave", name); 8 | }); 9 | }); 10 | 11 | if (window.location.hash) 12 | document.querySelector(window.location.hash).scrollIntoView(); 13 | -------------------------------------------------------------------------------- /site/static/style.css: -------------------------------------------------------------------------------- 1 | header { 2 | position: fixed; 3 | top: 0px; 4 | width: 100%; 5 | padding: 0 !important; 6 | height: 2.5rem; 7 | line-height: 2.5rem; 8 | background-color: white; 9 | border-bottom: 2px solid #dadada; 10 | } 11 | header .header-container { 12 | display: flex; 13 | justify-content: space-between; 14 | gap: 1rem; 15 | margin: 0 auto; 16 | align-items: center; 17 | } 18 | header .header-title { 19 | display: flex; 20 | gap: 1rem; 21 | } 22 | header .header-links { 23 | display: flex; 24 | padding-right: 2rem; 25 | } 26 | .title { 27 | height: 4rem; 28 | margin-bottom: 2rem; 29 | font-size: 1.3rem; 30 | } 31 | .title code { 32 | padding: 0.2rem; 33 | } 34 | .title-name code { 35 | color: var(--primary); 36 | } 37 | .title-version { 38 | font-size: 0.8rem; 39 | color: white; 40 | color: #2c2c2c; 41 | } 42 | 43 | main { 44 | min-width: 0; 45 | } 46 | main > aside nav { 47 | width: 100%; 48 | padding-bottom: var(--block-spacing-vertical); 49 | } 50 | main > aside nav.closed-on-mobile details { 51 | display: none; 52 | } 53 | @media (min-width: 992px) { 54 | body > main { 55 | --block-spacing-horizontal: calc(var(--spacing) * 1.75); 56 | grid-column-gap: calc(var(--block-spacing-horizontal) * 3); 57 | display: grid; 58 | grid-template-columns: 200px minmax(0, 1fr); 59 | } 60 | main > aside nav { 61 | position: fixed; 62 | width: 280px; 63 | max-height: calc(100vh - 5.5rem); 64 | overflow-x: hidden; 65 | overflow-y: auto; 66 | } 67 | main > aside nav.closed-on-mobile details { 68 | display: block; 69 | } 70 | } 71 | 72 | @media only screen and (prefers-color-scheme: dark) { 73 | :root:not([data-theme]) { 74 | --primary: #b45ea4; 75 | --primary-hover: #d0abcf; 76 | --primary-focus: rgba(180, 94, 164, 0.25); 77 | --primary-inverse: #fff; 78 | } 79 | } 80 | 81 | h1, 82 | h2, 83 | p { 84 | --typography-spacing-vertical: 1.25rem; 85 | } 86 | 87 | pre code { 88 | font-size: 0.9rem; 89 | } 90 | 91 | p, 92 | pre, 93 | code, 94 | h1, 95 | h2, 96 | h3, 97 | h4, 98 | h5, 99 | h6 { 100 | cursor: auto; 101 | } 102 | 103 | /* hljs stuff */ 104 | 105 | pre code.hljs { 106 | display: block; 107 | overflow-x: auto; 108 | padding: 1em; 109 | } 110 | code.hljs { 111 | padding: 3px 5px; 112 | } 113 | 114 | /* 115 | Adapted from "an old hope" 116 | https://github.com/highlightjs/highlight.js/blob/86dcb210227ef130a00b5ece50605ea1ec887be8/src/styles/an-old-hope.css#L7 117 | */ 118 | 119 | :root { 120 | --color-death-star: #b6b18b; 121 | --color-vader: #eb3c54; 122 | --color-c3po: #e7ce56; 123 | --color-skywalker: #ee7c2b; 124 | --color-kenobi: #4fb4d7; 125 | --color-yoda: #78bb65; 126 | --color-windu: #b45ea4; 127 | 128 | --hljs-background: #1c1d21; 129 | --hljs-color: #c0c5ce; 130 | 131 | --code-dotcommand: var(--color-skywalker); 132 | --code-variable: var(--color-kenobi); 133 | --code-keyword: var(--color-windu); 134 | --code-number: var(--color-c3po); 135 | --code-type: var(--color-skywalker); 136 | --code-builtin: var(--color-c3po); 137 | --code-string: var(--color-kenobi); 138 | --code-comment: var(--color-yoda); 139 | --code-prompt: #7c7c7c; 140 | } 141 | 142 | code { 143 | --code-color: #cecece; 144 | --code-color: #2c2c2c; 145 | } 146 | 147 | a, 148 | a code { 149 | color: var(--color-kenobi); 150 | } 151 | 152 | .hljs { 153 | background: var(--hljs-background); 154 | color: var(--hljs-color); 155 | } 156 | .hljs-prompt { 157 | color: var(--code-prompt); 158 | font-style: italic; 159 | user-select: none; 160 | } 161 | 162 | .hljs-dotcommand { 163 | color: var(--code-dotcommand); 164 | } 165 | .hljs-variable { 166 | color: var(--code-variable); 167 | } 168 | .hljs-number { 169 | color: var(--code-number); 170 | } 171 | 172 | .hljs-built_in { 173 | color: var(--code-builtin); 174 | } 175 | 176 | .hljs-string { 177 | color: var(--code-string); 178 | } 179 | .hljs-comment { 180 | color: var(--code-comment); 181 | } 182 | .hljs-keyword { 183 | color: var(--code-keyword); 184 | } 185 | 186 | .hljs-type { 187 | color: var(--code-type); 188 | } 189 | 190 | .hljs-quote { 191 | color: var(--color-death-star); 192 | } 193 | 194 | .hljs-template-variable, 195 | .hljs-tag, 196 | .hljs-name, 197 | .hljs-selector-id, 198 | .hljs-selector-class, 199 | .hljs-regexp, 200 | .hljs-deletion { 201 | color: var(--color-vader); 202 | } 203 | 204 | .hljs-literal, 205 | .hljs-params, 206 | .hljs-meta, 207 | .hljs-link { 208 | color: var(--color-c3po); 209 | } 210 | 211 | .hljs-attribute { 212 | color: var(--color-skywalker); 213 | } 214 | 215 | .hljs-symbol, 216 | .hljs-bullet, 217 | .hljs-addition { 218 | color: var(--color-kenobi); 219 | } 220 | 221 | .hljs-title, 222 | .hljs-section { 223 | color: var(--color-yoda); 224 | } 225 | 226 | .hljs-selector-tag { 227 | color: var(--code-keyword); 228 | } 229 | 230 | .hljs-emphasis { 231 | font-style: italic; 232 | } 233 | 234 | .hljs-strong { 235 | font-weight: bold; 236 | } 237 | -------------------------------------------------------------------------------- /site/usage/datasette.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Datasette 3 | order: 5 4 | --- 5 | 6 | # The `datasette-sqlite-jsonschema` Datasette Plugin 7 | 8 | `datasette-sqlite-jsonschema` is a [Datasette plugin](https://docs.datasette.io/en/stable/plugins.html) that loads the [`sqlite-jsonschema`](https://github.com/asg017/sqlite-jsonschema) extension in Datasette instances, allowing you to generate and work with [TODO](https://github.com/jsonschema/spec) in SQL. 9 | 10 | ``` 11 | datasette install datasette-sqlite-jsonschema 12 | ``` 13 | 14 | See [`docs.md`](../../docs.md) for a full API reference for the jsonschema SQL functions. 15 | 16 | Alternatively, when publishing Datasette instances, you can use the `--install` option to install the plugin. 17 | 18 | ``` 19 | datasette publish cloudrun data.db --service=my-service --install=datasette-sqlite-jsonschema 20 | 21 | ``` 22 | -------------------------------------------------------------------------------- /site/usage/deno.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Deno 3 | order: 3 4 | --- 5 | 6 | # `x/sqlite_jsonschema` Deno Module 7 | 8 | [![Tags](https://img.shields.io/github/release/asg017/sqlite-jsonschema)](https://github.com/asg017/sqlite-jsonschema/releases) 9 | [![Doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/sqlite-jsonschema@0.2.2/mod.ts) 10 | 11 | The [`sqlite-jsonschema`](https://github.com/asg017/sqlite-jsonschema) SQLite extension is available to Deno developers with the [`x/sqlite_jsonschema`](https://deno.land/x/sqlite-jsonschema) Deno module. It works with [`x/sqlite3`](https://deno.land/x/sqlite3), the fastest and native Deno SQLite3 module. 12 | 13 | ```typescript 14 | import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts"; 15 | import * as sqlite_jsonschema from "https://deno.land/x/sqlite_jsonschema@v0.2.2/mod.ts"; 16 | 17 | const db = new Database(":memory:"); 18 | 19 | db.enableLoadExtension = true; 20 | db.loadExtension(sqlite_jsonschema.getLoadablePath()); 21 | 22 | const [version] = db.prepare("select jsonschema_version()").value<[string]>()!; 23 | 24 | console.log(version); 25 | ``` 26 | 27 | Like `x/sqlite3`, `x/sqlite_jsonschema` requires network and filesystem permissions to download and cache the pre-compiled SQLite extension for your machine. Though `x/sqlite3` already requires `--allow-ffi` and `--unstable`, so you might as well use `--allow-all`/`-A`. 28 | 29 | ```bash 30 | deno run -A --unstable 31 | ``` 32 | 33 | `x/sqlite_jsonschema` does not work with [`x/sqlite`](https://deno.land/x/sqlite@v3.7.0), which is a WASM-based Deno SQLite module that does not support loading extensions. 34 | -------------------------------------------------------------------------------- /site/usage/hljs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: highlight.js stuff 3 | order: 99 4 | --- 5 | 6 | Column types are highlighted correctly in `CREATE TABLE` statements. 7 | 8 | ```sql 9 | create table students( 10 | name text, 11 | age int, 12 | progress decimal(20), 13 | data json 14 | ); 15 | ``` 16 | 17 | `CREATE VIRTUAL TABLE` statements, which are unique to SQLite, is also highlighted correctly. 18 | 19 | ```sql 20 | 21 | create virtual table fts_emails using fts5(name, email, body); 22 | 23 | ``` 24 | 25 | All builtin functions to _most_ SQLite builds and most shell builtin functions are highlighted as well. 26 | 27 | ```sql 28 | 29 | select 30 | 31 | -- all SQLite builtins functions are supported 32 | sqlite_version(), 33 | datetime() as created_at, 34 | format('%s %s', first_name, last_name) as name, 35 | max(age) as oldest, 36 | 37 | -- As well as JSON functions, including the new ->/->> syntax! 38 | json_extract(data, '$.email') as email, 39 | data ->> 'mailing_address' as mailing_address 40 | from students 41 | -- and builtin table functions! 42 | join json_each(students.assignments, '$.data') 43 | 44 | ``` 45 | 46 | If you include the `sqlite>` prompt prefix from the SQLite CLI, it will appear lighter and _is not copy+pasteable!_ Dot commands also have special highlighting. 47 | 48 | ```sql 49 | sqlite> .load regex0 50 | sqlite> .header on 51 | sqlite> .mode quote 52 | sqlite> select count(*) from students; 53 | 123 54 | ``` 55 | 56 | xxx 57 | 58 | ```sql 59 | 60 | ``` 61 | -------------------------------------------------------------------------------- /site/usage/loadable.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: As a Loadable Extension 3 | order: 99 4 | --- 5 | 6 | # Using `sqlite-jsonschema` as a Loadable Extension 7 | 8 | - c API 9 | - Ruby 10 | - 11 | -------------------------------------------------------------------------------- /site/usage/node.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Node.js 3 | order: 2 4 | --- 5 | 6 | # Node.js 7 | -------------------------------------------------------------------------------- /site/usage/python.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python 3 | order: 1 4 | --- 5 | 6 | # The `sqlite-jsonschema` Python package 7 | 8 | `sqlite-jsonschema` is also distributed on PyPi as a Python package, for use in Python applications. It works well with the builtin [`sqlite3`](https://docs.python.org/3/library/sqlite3.html) Python module. 9 | 10 | ``` 11 | pip install sqlite-jsonschema 12 | ``` 13 | 14 | ## Usage 15 | 16 | The `sqlite-jsonschema` python package exports two functions: `loadable_path()`, which returns the full path to the loadable extension, and `load(conn)`, which loads the `sqlite-jsonschema` extension into the given [sqlite3 Connection object](https://docs.python.org/3/library/sqlite3.html#connection-objects). 17 | 18 | ```python 19 | import sqlite_jsonschema 20 | print(sqlite_jsonschema.loadable_path()) 21 | 22 | 23 | import sqlite3 24 | conn = sqlite3.connect(':memory:') 25 | sqlite_jsonschema.load(conn) 26 | conn.execute('select jsonschema_version(), jsonschema()').fetchone() 27 | # ('v0.1.0', '01gr7gwc5aq22ycea6j8kxq4s9') 28 | ``` 29 | 30 | See [the full API Reference](#api-reference) for the Python API, and [`docs.md`](../../docs.md) for documentation on the `sqlite-jsonschema` SQL API. 31 | 32 | See [`datasette-sqlite-jsonschema`](../datasette_sqlite_jsonschema/) for a Datasette plugin that is a light wrapper around the `sqlite-jsonschema` Python package. 33 | 34 | ## Compatibility 35 | 36 | Currently the `sqlite-jsonschema` Python package is only distributed on PyPi as pre-build wheels, it's not possible to install from the source distribution. This is because the underlying `sqlite-jsonschema` extension requires a lot of build dependencies like `make`, `cc`, and `cargo`. 37 | 38 | If you get a `unsupported platform` error when pip installing `sqlite-jsonschema`, you'll have to build the `sqlite-jsonschema` manually and load in the dynamic library manually. 39 | 40 | ## API Reference 41 | 42 |

loadable_path()

43 | 44 | Returns the full path to the locally-install `sqlite-jsonschema` extension, without the filename. 45 | 46 | This can be directly passed to [`sqlite3.Connection.load_extension()`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.load_extension), but the [`sqlite_jsonschema.load()`](#load) function is preferred. 47 | 48 | ```python 49 | import sqlite_jsonschema 50 | print(sqlite_jsonschema.loadable_path()) 51 | 52 | ``` 53 | 54 | > Note: this extension path doesn't include the file extension (`.dylib`, `.so`, `.dll`). This is because [SQLite will infer the correct extension](https://www.sqlite.org/loadext.html#loading_an_extension). 55 | 56 |

load(connection)

57 | 58 | Loads the `sqlite-jsonschema` extension on the given [`sqlite3.Connection`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection) object, calling [`Connection.load_extension()`](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.load_extension). 59 | 60 | ```python 61 | import sqlite_jsonschema 62 | import sqlite3 63 | conn = sqlite3.connect(':memory:') 64 | 65 | conn.enable_load_extension(True) 66 | sqlite_jsonschema.load(conn) 67 | conn.enable_load_extension(False) 68 | 69 | conn.execute( 70 | 'select jsonschema_version(), jsonschema()' 71 | ).fetchone() 72 | # ('v0.1.0', '01gr7gwc5aq22ycea6j8kxq4s9') 73 | ``` 74 | -------------------------------------------------------------------------------- /site/usage/source.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Build from Source 3 | order: 99 4 | --- 5 | 6 | # Building from Source 7 | 8 | In order to 9 | 10 | ```bash 11 | git clone https://github.com/asg017/sqlite-jsonschema TODO 12 | ``` 13 | 14 | ```bash 15 | cd sqlite-jsonschema 16 | make loadable-release 17 | ``` 18 | 19 | ```bash 20 | ls dist/release 21 | ``` 22 | 23 | `.dylib`, `.so`, `.dll`. 24 | -------------------------------------------------------------------------------- /site/usage/sqlite3.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: sqlite3 CLI 3 | order: 4 4 | --- 5 | 6 | # `sqlite3` CLI 7 | 8 | To use `sqlite-jsonschema` with the [`sqlite3` command line interface](https://sqlite.org/cli.html), either download a pre-compiled extension for your machine [from a Github Release](https://github.com/asg017/sqlite-jsonschema/releases), or [compile your own version](./source.html). 9 | 10 | Once you have a `jsonschema0.so`, `jsonschema0.dylib`, or `jsonschema0.dll` extension, use the [`.load` command](https://sqlite.org/cli.html#loading_extensions) in the `sqlite3` CLI to load the extension into your connection. 11 | 12 | ```sql 13 | sqlite> .load ./jsonschema0 14 | sqlite> select jsonschema_version(); 15 | 'v0.2.1' 16 | ``` 17 | 18 | You can include `.load ./jsonschema0` at the top of your `.sql` scripts to load `sqlite-jsonschema` into your projects. 19 | 20 | In `build.sql`: 21 | 22 | ```sql 23 | .bail on 24 | 25 | .load ./jsonschema0 26 | 27 | select jsonschema_version(); 28 | ``` 29 | 30 | Then run with: 31 | 32 | ```bash 33 | sqlite3 :memory: '.read build.sql' 34 | ``` 35 | -------------------------------------------------------------------------------- /src/jsonschema.rs: -------------------------------------------------------------------------------- 1 | use std::os::raw::c_void; 2 | 3 | use jsonschema::JSONSchema; 4 | use sqlite_loadable::prelude::*; 5 | use sqlite_loadable::{api, Error, Result}; 6 | 7 | pub fn jsonschema_matches( 8 | context: *mut sqlite3_context, 9 | values: &[*mut sqlite3_value], 10 | ) -> Result<()> { 11 | let (schema, input_type) = jsonschema_from_value_or_cache(context, values, 0)?; 12 | let instance = api::value_text( 13 | values 14 | .get(1) 15 | .ok_or_else(|| Error::new_message("expected 2nd argument as contents"))?, 16 | )?; 17 | let instance = serde_json::from_str(instance) 18 | .map_err(|e| Error::new_message(format!("Invalid JSON: {}", e).as_str()))?; 19 | api::result_bool(context, schema.is_valid(&instance)); 20 | cleanup_regex_value_cached(context, schema, input_type); 21 | Ok(()) 22 | } 23 | 24 | pub enum RegexInputType { 25 | TextInitial(usize), 26 | GetAuxdata, 27 | } 28 | pub fn jsonschema_from_value_or_cache( 29 | context: *mut sqlite3_context, 30 | values: &[*mut sqlite3_value], 31 | at: usize, 32 | ) -> Result<(Box, RegexInputType)> { 33 | let value = values 34 | .get(at) 35 | .ok_or_else(|| Error::new_message("expected 1st argument as pattern"))?; 36 | 37 | // Step 1: If sqlite3_get_auxdata returns a pointer, then use that. 38 | let auxdata = api::auxdata_get(context, at as i32); 39 | if !auxdata.is_null() { 40 | Ok(( 41 | unsafe { Box::from_raw(auxdata.cast::()) }, 42 | RegexInputType::GetAuxdata, 43 | )) 44 | } else { 45 | // Step 3: if a string is passed in, then try to make 46 | // a regex from that, and return a flag to call sqlite3_set_auxdata 47 | 48 | let schema = api::value_text(value)?; 49 | let schema = 50 | serde_json::from_str(schema).map_err(|_| Error::new_message("Invalid JSON"))?; 51 | let schema = 52 | JSONSchema::compile(&schema).map_err(|_| Error::new_message("Invalid schema"))?; 53 | Ok((Box::new(schema), RegexInputType::TextInitial(at))) 54 | } 55 | } 56 | 57 | unsafe extern "C" fn cleanup(p: *mut c_void) { 58 | drop(Box::from_raw(p.cast::<*mut JSONSchema>())) 59 | } 60 | 61 | pub fn cleanup_regex_value_cached( 62 | context: *mut sqlite3_context, 63 | regex: Box, 64 | input_type: RegexInputType, 65 | ) { 66 | let pointer = Box::into_raw(regex); 67 | match input_type { 68 | RegexInputType::GetAuxdata => {} 69 | RegexInputType::TextInitial(at) => { 70 | api::auxdata_set( 71 | context, 72 | at as i32, 73 | pointer.cast::(), 74 | // TODO memory leak, box not destroyed? 75 | Some(cleanup), 76 | ) 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | mod jsonschema; 2 | 3 | use crate::jsonschema::jsonschema_matches; 4 | 5 | use sqlite_loadable::prelude::*; 6 | use sqlite_loadable::{api, define_scalar_function, Result}; 7 | 8 | pub fn jsonschema_version( 9 | context: *mut sqlite3_context, 10 | _values: &[*mut sqlite3_value], 11 | ) -> Result<()> { 12 | api::result_text(context, format!("v{}", env!("CARGO_PKG_VERSION")))?; 13 | Ok(()) 14 | } 15 | 16 | pub fn jsonschema_debug( 17 | context: *mut sqlite3_context, 18 | _values: &[*mut sqlite3_value], 19 | ) -> Result<()> { 20 | api::result_text( 21 | context, 22 | format!( 23 | "Version: v{} 24 | Source: {} 25 | ", 26 | env!("CARGO_PKG_VERSION"), 27 | env!("GIT_HASH") 28 | ), 29 | )?; 30 | Ok(()) 31 | } 32 | 33 | #[sqlite_entrypoint] 34 | pub fn sqlite3_jsonschema_init(db: *mut sqlite3) -> Result<()> { 35 | define_scalar_function( 36 | db, 37 | "jsonschema_version", 38 | 0, 39 | jsonschema_version, 40 | FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC, 41 | )?; 42 | define_scalar_function( 43 | db, 44 | "jsonschema_debug", 45 | 0, 46 | jsonschema_debug, 47 | FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC, 48 | )?; 49 | define_scalar_function( 50 | db, 51 | "jsonschema_matches", 52 | 2, 53 | jsonschema_matches, 54 | FunctionFlags::UTF8, 55 | )?; 56 | 57 | Ok(()) 58 | } 59 | -------------------------------------------------------------------------------- /tests/test-loadable.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import unittest 3 | import time 4 | import os 5 | 6 | EXT_PATH="./dist/debug/jsonschema0" 7 | 8 | def connect(ext): 9 | db = sqlite3.connect(":memory:") 10 | 11 | db.execute("create table base_functions as select name from pragma_function_list") 12 | db.execute("create table base_modules as select name from pragma_module_list") 13 | 14 | db.enable_load_extension(True) 15 | db.load_extension(ext) 16 | 17 | db.execute("create temp table loaded_functions as select name from pragma_function_list where name not in (select name from base_functions) order by name") 18 | db.execute("create temp table loaded_modules as select name from pragma_module_list where name not in (select name from base_modules) order by name") 19 | 20 | db.row_factory = sqlite3.Row 21 | return db 22 | 23 | 24 | db = connect(EXT_PATH) 25 | 26 | def explain_query_plan(sql): 27 | return db.execute("explain query plan " + sql).fetchone()["detail"] 28 | 29 | def execute_all(sql, args=None): 30 | if args is None: args = [] 31 | results = db.execute(sql, args).fetchall() 32 | return list(map(lambda x: dict(x), results)) 33 | 34 | FUNCTIONS = [ 35 | "jsonschema_debug", 36 | "jsonschema_matches", 37 | "jsonschema_version", 38 | ] 39 | 40 | MODULES = [] 41 | class TestJsonschema(unittest.TestCase): 42 | def test_funcs(self): 43 | funcs = list(map(lambda a: a[0], db.execute("select name from loaded_functions").fetchall())) 44 | self.assertEqual(funcs, FUNCTIONS) 45 | 46 | def test_modules(self): 47 | modules = list(map(lambda a: a[0], db.execute("select name from loaded_modules").fetchall())) 48 | self.assertEqual(modules, MODULES) 49 | 50 | def test_jsonschema_version(self): 51 | self.assertEqual(db.execute("select jsonschema_version()").fetchone()[0][0], "v") 52 | 53 | def test_jsonschema_debug(self): 54 | debug = db.execute("select jsonschema_debug()").fetchone()[0] 55 | self.assertEqual(len(debug.splitlines()), 2) 56 | 57 | def test_jsonschema_matches(self): 58 | jsonschema_matches = lambda schema, instance: db.execute("select jsonschema_matches(?, ?)", [schema, instance]).fetchone()[0] 59 | self.assertEqual(jsonschema_matches('{"maxLength": 5}', '"aaaaa"'), 1) 60 | self.assertEqual(jsonschema_matches('{"maxLength": 5}', '"aaaaaa"'), 0) 61 | 62 | matches_all = lambda schema, data: execute_all("select value, jsonschema_matches(?, json_quote(value)) as result from json_each(?)", [schema, data]) 63 | 64 | self.assertEqual( 65 | matches_all('{"maxLength": 3}', '["a", "bb", "ccc", "dddd"]'), 66 | [ 67 | {"value": "a", "result": 1}, 68 | {"value": "bb", "result": 1}, 69 | {"value": "ccc", "result": 1}, 70 | {"value": "dddd", "result": 0}, 71 | ] 72 | ) 73 | 74 | 75 | 76 | class TestCoverage(unittest.TestCase): 77 | def test_coverage(self): 78 | test_methods = [method for method in dir(TestJsonschema) if method.startswith('test_')] 79 | funcs_with_tests = set([x.replace("test_", "") for x in test_methods]) 80 | 81 | for func in FUNCTIONS: 82 | self.assertTrue(func in funcs_with_tests, f"{func} does not have corresponding test in {funcs_with_tests}") 83 | 84 | for module in MODULES: 85 | self.assertTrue(module in funcs_with_tests, f"{module} does not have corresponding test in {funcs_with_tests}") 86 | 87 | if __name__ == '__main__': 88 | unittest.main() -------------------------------------------------------------------------------- /tests/test-python.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import sqlite3 3 | import sqlite_jsonschema 4 | 5 | class TestSqlitejsonschemaPython(unittest.TestCase): 6 | def test_path(self): 7 | db = sqlite3.connect(':memory:') 8 | db.enable_load_extension(True) 9 | 10 | self.assertEqual(type(sqlite_jsonschema.loadable_path()), str) 11 | 12 | sqlite_jsonschema.load(db) 13 | version, = db.execute('select jsonschema_version()').fetchone() 14 | self.assertEqual(version[0], "v") 15 | 16 | if __name__ == '__main__': 17 | unittest.main() --------------------------------------------------------------------------------