https://github.com/riyaz-ali/sqlite
Golang library to build sqlite extensions :rocket:
https://github.com/riyaz-ali/sqlite
golang golang-library sqlite-virtual-table sqlite3 sqlite3-extension
Last synced: 9 months ago
JSON representation
Golang library to build sqlite extensions :rocket:
- Host: GitHub
- URL: https://github.com/riyaz-ali/sqlite
- Owner: riyaz-ali
- License: other
- Created: 2020-10-17T06:35:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-04T09:10:32.000Z (about 1 year ago)
- Last Synced: 2025-04-23T21:18:42.183Z (10 months ago)
- Topics: golang, golang-library, sqlite-virtual-table, sqlite3, sqlite3-extension
- Language: Go
- Homepage: https://go.riyazali.net/sqlite
- Size: 2.43 MB
- Stars: 169
- Watchers: 7
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQLite Extensions
[](https://golang.org/doc/go1.14)
[](https://golang.org/doc/go1.14)
[](https://pkg.go.dev/go.riyazali.net/sqlite)
## Overview
**`sqlite`** package provides a low-level interface that allows you to build [**`sqlite`** extensions](https://www.sqlite.org/loadext.html) that [_can be loaded dynamically at runtime_](https://www.sqlite.org/loadext.html#loading_an_extension)
or [_linked statically at build-time_](https://www.sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension) (experimental)
## Installation
This package can be installed with `go get` as:
```shell
$ go get -u go.riyazali.net/sqlite
```
**`sqlite`** is a `cgo` package and requires a working `c` compiler.
## Usage
To build an `sqlite` extension, you need to build your project with [`-buildmode=c-shared`](https://golang.org/cmd/go/#hdr-Build_modes). That would emit
a **`.so`** file (or **`.dll`** on windows), which you can then [_load into `sqlite`_](https://www.sqlite.org/c3ref/load_extension.html).
Consider as an example, the [sample `upper`](_examples/upper/upper.go) module in `_examples/`. To build it, you'd use something similar to:
```shell
$ go build -buildmode=c-shared -o upper.so _examples/upper
```
which would emit an `upper.so` in the current directory. Now, to use it with (say) the `sqlite3` shell, you could do something like
```shell
$ sqlite3
> .load upper.so
> SELECT upper("sqlite3");
SQLITE3
> .exit
```
## Features
- [x] [`commit` / `rollback` hooks](https://www.sqlite.org/c3ref/commit_hook.html)
- [x] custom [`collation`](https://www.sqlite.org/c3ref/create_collation.html)
- [x] custom [`scalar`, `aggregate` and `window` functions](https://www.sqlite.org/appfunc.html)
- [x] custom [`virtual table`](https://www.sqlite.org/vtab.html) does not support `xShadowName` and nested transations _yet_
Each of the support feature provides an exported interface that the user code must implement. Refer to code and [godoc](https://pkg.go.dev/go.riyazali.net/sqlite)
for more details.
## License
MIT License Copyright (c) 2020 Riyaz Ali
Refer to [LICENSE](./LICENSE) for full text.