### Run Go Quickstart Example
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Build the Go quickstart example using the mattn/go-sqlite3 driver with the libsqlite3 build tag.
```bash
cd examples/go
CGO_CFLAGS="-I../../build" CGO_LDFLAGS="../../build/libdoltlite.a -lz -lpthread" \
go build -tags libsqlite3 -o quickstart .
./quickstart
```
--------------------------------
### Run Python Quickstart Example
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Install the doltlite package and run the Python quickstart example. Requires a Python environment that supports dynamic linking of libsqlite3.
```bash
pip install doltlite
python3 examples/quickstart.py
```
--------------------------------
### Run C Quickstart Example
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Compile and execute the C quickstart example using the built DoltLite library.
```bash
cd build
gcc -o quickstart ../examples/quickstart.c -I. libdoltlite.a -lpthread -lz
./quickstart
```
--------------------------------
### Build SQLite Extension (Unix Example)
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/tea/README.txt
Example of building the SQLite extension on a Unix system, including changing directory, configuring, testing, and installing.
```bash
$ cd sqlite-*-tea
$ ./configure --with-tcl=/path/to/tcl/install/root
$ make test
$ make install
```
--------------------------------
### Install Tcl
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Install the configured Tcl build to the specified home directory.
```bash
make install
```
--------------------------------
### Installing and Verifying Autosetup Update
Source: https://github.com/dolthub/doltlite/blob/master/autosetup/README.md
Steps to install the updated autosetup into a project and verify the changes using 'fossil status'.
```bash
$ /path/to/autosetup-checkout/autosetup --install .
$ fossil status # show the modified files
```
--------------------------------
### Example Hexdump Database Input
Source: https://github.com/dolthub/doltlite/blob/master/tool/dbtotxt.md
This example demonstrates how to embed a small test database directly into a script using the dbtotxt format. The input starts with metadata and is followed by page data, terminated by '| end'.
```sqlite
.open --hexdb
| size 8192 pagesize 4096 filename x9.db
| page 1 offset 0
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
| 16: 10 00 01 01 00 40 20 20 00 00 00 04 00 00 00 02 .....@ ........
| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................
| 96: 00 2e 30 38 0d 00 00 00 01 0f c0 00 0f c0 00 00 ..08............
| 4032: 3e 01 06 17 11 11 01 69 74 61 62 6c 65 74 31 74 >......itablet1t
| 4048: 31 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 1.CREATE TABLE t
| 4064: 31 28 78 2c 79 20 44 45 46 41 55 4c 54 20 78 27 1(x,y DEFAULT x'
| 4080: 66 66 27 2c 7a 20 44 45 46 41 55 4c 54 20 30 29 ff',z DEFAULT 0)
| page 2 offset 4096
| 0: 0d 08 14 00 04 00 10 00 0e 05 0a 0f 04 15 00 10 ................
| 16: 88 02 03 05 90 04 0e 08 00 00 00 00 00 00 00 00 ................
| 1040: 00 00 00 00 ff 87 7c 02 05 8f 78 0e 08 00 00 00 ......|...x.....
| 2064: 00 00 00 ff 0c 0a 01 fb 00 00 00 00 00 00 00 00 ................
| 2560: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 83 ................
| 2576: 78 01 05 87 70 0e 08 00 00 00 00 00 00 00 00 00 x...p...........
| 3072: 00 00 00 00 00 00 00 00 00 ff 00 00 01 fb 00 00 ................
| 3584: 00 00 00 00 00 83 78 00 05 87 70 0e 08 00 00 00 ......x...p.....
| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ................
end x9.db
SELECT rowid FROM t1;
PRAGMA integrity_check;
```
--------------------------------
### Remote Server Setup for WASM Build
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README.md
Commands to install prerequisites and build the WASM module on the remote server.
```bash
Remote: Install git, emsdk, and althttpd
* Use a [version of althttpd][althttpd] from
September 26, 2022 or newer.
* Remote: Install the SQLite source tree. CD to ext/wasm
* Remote: "`make`" to build WASM
```
--------------------------------
### Install TCL development libraries
Source: https://github.com/dolthub/doltlite/blob/master/doc/compile-for-windows.md
Commands to compile and install TCL from source using nmake.
```batch
nmake /f makefile.vc INSTALLDIR=c:\Tcl release
```
```batch
nmake /f makefile.vc INSTALLDIR=c:\Tcl install
```
--------------------------------
### Preferred Build: Install Tcl Extension (Unix)
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/tea/README.txt
Installs the Tcl extension after it has been configured and built using the preferred method on Unix.
```bash
make tclextension-install
```
--------------------------------
### Get Autosetup Reference
Source: https://github.com/dolthub/doltlite/blob/master/autosetup/README.md
Display the reference documentation for the Autosetup API. This command includes documentation from TCL files in the ./autosetup directory.
```bash
$ ./configure --reference | less
```
--------------------------------
### Install Emscripten SDK
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README.md
Steps to clone the Emscripten repository, install the latest SDK tools, and activate it for the current user on a Linux environment.
```bash
# Clone the emscripten repository:
$ sudo apt install git
$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
# Download and install the latest SDK tools:
$ ./emsdk install latest
# Make the "latest" SDK "active" for the current user:
$ ./emsdk activate latest
```
--------------------------------
### Install TCL Extension
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Installs the SQLite TCL extension using nmake.
```batch
nmake /f Makefile.msc tclextension-install
```
--------------------------------
### Configure SQLite with custom CFLAGS and defines
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/README.txt
Example of passing both optimization flags and preprocessor defines to the configure script.
```bash
$ CFLAGS="-Os -DSQLITE_OMIT_DEPRECATED" ./configure
```
--------------------------------
### Preferred Build: Install Tcl Extension (Windows)
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/tea/README.txt
Installs the Tcl extension on Windows using nmake, specifying the Tclsh command.
```bash
nmake /f Makefile.msc tclextension-install TCLSH_CMD=$(TCLSH)
```
--------------------------------
### Install @dolthub/doltlite-wasm
Source: https://github.com/dolthub/doltlite/blob/master/packaging/npm/README.md
Install the package using npm.
```bash
npm install @dolthub/doltlite-wasm
```
--------------------------------
### List Installed SQLite TCL Extensions
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Verify the correct installation of the TCL extension by listing it.
```bash
make tclextension-list
```
--------------------------------
### Configure, Test, and Uninstall Teaish Build
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
This command configures, tests, installs, and then uninstalls the teaish build. It is important to note that parallel builds (`-j#`) should not be used with this command as it can lead to race conditions during installation and uninstallation.
```bash
./configure --with-tcl=$TCLHOME
make uninstall
```
--------------------------------
### Configure Remote Server
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Commands for starting the standalone remote server with various security configurations.
```bash
./doltlite-remotesrv -p 8080 /path/to/databases/
./doltlite-remotesrv -p 8080 --bind 0.0.0.0 /path/to/databases/ # all interfaces
./doltlite-remotesrv -p 8443 --bind 0.0.0.0 \
--cert server.crt --key server.key \
--auth-keys /path/to/authorized-keys --audience db.example.com \
/path/to/databases/
```
--------------------------------
### Build with Visual C++ and specific defines
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/README.txt
Example of passing preprocessor defines to the NMAKE build process on Windows using the OPTS macro.
```bash
"OPTS=-DSQLITE_ENABLE_STAT4=1 -DSQLITE_OMIT_JSON=1"
```
--------------------------------
### Serve WASM Demo Applications with make httpd
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README.md
A simpler command to start an HTTP server from the ext/wasm directory to serve the demo applications.
```bash
# Or, more simply, from the ext/wasm dir:
$ make httpd
```
--------------------------------
### Build and Test SQLite Extension (Unix)
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/tea/README.txt
After configuration, build the SQLite extension and run tests to ensure correctness. Then, install the extension.
```bash
make test
make install
```
--------------------------------
### Alignment Combination Example
Source: https://github.com/dolthub/doltlite/blob/master/ext/qrf/README.md
Demonstrates how alignment constants can be combined to form a specific alignment.
```c
QRF_ALIGN_Center + QRF_ALIGN_Bottom == QRF_ALIGN_S.
```
--------------------------------
### Install TCL 8.6
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Installs the built TCL 8.6. This must be invoked separately from the 'release' target.
```batch
nmake /f makefile.vc install
```
--------------------------------
### Set Target Include Directories and Install Rules
Source: https://github.com/dolthub/doltlite/blob/master/ext/mbedtls/library/CMakeLists.txt
Configures include paths, compile definitions, and installation targets for all MbedTLS library targets.
```cmake
foreach(target IN LISTS target_libraries)
add_library(MbedTLS::${target} ALIAS ${target}) # add_subdirectory support
# Include public header files from /include and other directories
# declared by /3rdparty/**/CMakeLists.txt. Include private header files
# from /library and others declared by /3rdparty/**/CMakeLists.txt.
# /library needs to be listed explicitly when building .c files outside
# of /library (which currently means: under /3rdparty).
target_include_directories(${target}
PUBLIC $
$
PRIVATE ${MBEDTLS_DIR}/library/
# Needed to include psa_crypto_driver_wrappers.h
${CMAKE_CURRENT_BINARY_DIR})
# Pass-through MBEDTLS_CONFIG_FILE and MBEDTLS_USER_CONFIG_FILE
if(MBEDTLS_CONFIG_FILE)
target_compile_definitions(${target}
PUBLIC MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
endif()
if(MBEDTLS_USER_CONFIG_FILE)
target_compile_definitions(${target}
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
endif()
install(
TARGETS ${target}
EXPORT MbedTLSTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach(target)
```
--------------------------------
### Configure and Test Teaish Build
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
This command configures, tests, and installs the teaish build of the extension. Ensure you are in the 'mkpkg_tmp/tea' directory and have set the TCLHOME environment variable.
```bash
./configure --with-tcl=$TCLHOME
make test install
```
--------------------------------
### Install DoltLite on Debian/Ubuntu
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Download and install the latest .deb packages for Debian or Ubuntu systems.
```bash
VER=$(curl -fsSL https://api.github.com/repos/dolthub/doltlite/releases/latest | jq -r .tag_name | sed 's/^v//')
ARCH=amd64 # or arm64
BASE=https://github.com/dolthub/doltlite/releases/download/v${VER}
wget ${BASE}/libdoltlite0_${VER}_${ARCH}.deb ${BASE}/doltlite_${VER}_${ARCH}.deb
sudo dpkg -i libdoltlite0_*.deb doltlite_*.deb
```
--------------------------------
### Build statically linked SQLite utility
Source: https://github.com/dolthub/doltlite/blob/master/doc/compile-for-windows.md
Example command to build sqlite3_analyzer.exe with static TCL linking enabled.
```batch
nmake /f Makefile.msc STATICALLY_LINK_TCL=1 sqlite3_analyzer.exe
```
--------------------------------
### Run Release Tests with Pattern Matching
Source: https://github.com/dolthub/doltlite/blob/master/doc/testrunner.md
Patterns can be appended to commands like 'release' to match specific Tcl tests and fuzz tests. This example runs release tests and specifically targets tests matching 'rtree%'.
```bash
test/testrunner.tcl release rtree%
```
--------------------------------
### Customizing Flag Defaults in Autosetup
Source: https://github.com/dolthub/doltlite/blob/master/autosetup/README.md
Example of how to define default values for flags within a custom Tcl script for autosetup.
```tcl
proc sqlite-custom-flags {} {
# If any existing --flags require different default values
# then call:
options-defaults {
flag-name new-default-value
...
}
# ^^^ That will replace the default value but will not update
# the --help text, which may lead to some confusion:
# https://github.com/msteveb/autosetup/issues/77
return {
{*} { # see below
new-flag-name => {Help text}
...
}
};
}
```
--------------------------------
### Configure SQLite with Tcl Support
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Configure SQLite to use the installed Tcl, enabling all features.
```bash
./configure --with-tcl=$TCLHOME --all
```
--------------------------------
### Specify Start Symbol
Source: https://github.com/dolthub/doltlite/blob/master/doc/lemon.html
Use %start_symbol followed by a non-terminal name to designate it as the grammar's start symbol, overriding the default first non-terminal.
```lemon
%start_symbol prog
```
--------------------------------
### Run Fuzz Tests via Environment Variable
Source: https://github.com/dolthub/doltlite/blob/master/doc/testrunner.md
This demonstrates running fuzz tests using the FUZZDB environment variable, which is an alternative to the command-line option. This example is shown in the context of a 'make releasetest' command.
```bash
FUZZDB=../fuzz/20250415.db make releasetest
```
--------------------------------
### Development Testing of Teaish Build
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
When actively developing the teaish build, use this command to ensure the build process correctly handles the temporary directory. It includes CFLAGS=-O0 for debugging and performs configuration, testing, installation, and uninstallation.
```bash
cd $PWD && ./configure CFLAGS=-O0 --with-tcl=$TCLHOME && make test install uninstall
```
--------------------------------
### Emscripten-style Configuration
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/jaccwabyt/jaccwabyt.md
Example configuration for StructBinderFactory using typical Emscripten WASM module properties. This setup provides the necessary heap, allocation, and deallocation functions.
```javascript
{
heap: Module?.asm?.memory || Module['wasmMemory'],
//Or:
// heap: ()=>Module['HEAP8'],
alloc: (n)=>Module['_malloc'](n),
dealloc: (m)=>Module['_free'](m)
}
```
--------------------------------
### Initialize Database in Browser
Source: https://github.com/dolthub/doltlite/blob/master/packaging/npm/README.md
Initialize the database with OPFS support for persistence. Requires cross-origin isolation headers.
```javascript
import { sqlite3InitModule } from '@dolthub/doltlite-wasm';
const sqlite3 = await sqlite3InitModule();
// Persistent across reloads when OPFS is available, in-memory otherwise.
const db = ('opfs' in sqlite3)
? new sqlite3.oo1.OpfsDb('/app.db')
: new sqlite3.oo1.DB(':memory:');
db.exec(`CREATE TABLE IF NOT EXISTS t(id INTEGER PRIMARY KEY, msg TEXT)`);
db.exec(`INSERT INTO t(msg) VALUES('hello')`);
db.exec(`SELECT dolt_commit('-A', '-m', 'first commit')`);
for (const row of db.selectObjects(`SELECT * FROM dolt_log`)) {
console.log(row.commit_hash, row.message);
}
```
--------------------------------
### Remove Old Tcl Installation
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Ensure no stale Tcl installation exists by removing the target installation directory.
```bash
rm -fr $TCLHOME
```
--------------------------------
### Cloning and Updating Autosetup Repository
Source: https://github.com/dolthub/doltlite/blob/master/autosetup/README.md
Instructions for cloning the autosetup git repository or updating an existing local copy.
```bash
$ git clone https://github.com/msteveb/autosetup
$ cd autosetup
# Or, if it's already checked out:
$ git pull
```
--------------------------------
### Configure Mbed TLS Header Installation
Source: https://github.com/dolthub/doltlite/blob/master/ext/mbedtls/include/CMakeLists.txt
Defines an option to install Mbed TLS headers and specifies the installation paths and permissions.
```cmake
option(INSTALL_MBEDTLS_HEADERS "Install Mbed TLS headers." ON)
if(INSTALL_MBEDTLS_HEADERS)
file(GLOB headers "mbedtls/*.h")
file(GLOB psa_headers "psa/*.h")
install(FILES ${headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mbedtls
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
install(FILES ${psa_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/psa
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endif(INSTALL_MBEDTLS_HEADERS)
```
--------------------------------
### Install DoltLite via Shell Script
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Use this command to install DoltLite on macOS or Linux systems using the provided installation script.
```bash
sudo bash -c 'curl -fsSL https://github.com/dolthub/doltlite/releases/latest/download/install.sh | bash'
```
--------------------------------
### Initialize Database in Node or Bun
Source: https://github.com/dolthub/doltlite/blob/master/packaging/npm/README.md
Initialize the database for use in Node.js or Bun environments.
```javascript
import { sqlite3InitModule } from '@dolthub/doltlite-wasm';
const sqlite3 = await sqlite3InitModule();
const db = new sqlite3.oo1.DB('/tmp/app.db');
db.exec(`CREATE TABLE t(x)`);
db.exec(`SELECT dolt_commit('-A', '-m', 'init')`);
```
--------------------------------
### Verify TCL Extension Installation
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Verifies the installation of the SQLite TCL extension.
```batch
nmake /f Makefile.msc tclextension-verify
```
--------------------------------
### Serve Demo Apps with althttpd
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README-dist.txt
A simple command to serve the demo applications using althttpd, enabling necessary features for WASM/JS builds.
```bash
althttpd --enable-sab --page index.html
```
--------------------------------
### Set TCL 9.0 Installation Directory
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Sets the environment variable for the TCL 9.0 installation directory.
```batch
set INSTALLDIR=%TCLBUILD%\tcl90
```
--------------------------------
### Set TCL 8.6 Installation Directory
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Sets the environment variable for the TCL 8.6 installation directory.
```batch
set INSTALLDIR=%TCLBUILD%\tcl86
```
--------------------------------
### Remove Test Tcl Installation Directory
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Clean up by removing the temporary Tcl installation directory after testing.
```bash
rm -rf $TCLHOME
```
--------------------------------
### Build WASM Components in ext/wasm
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README.md
Build the WASM components by navigating to the ext/wasm directory and running the make command.
```bash
cd ext/wasm
$ make
```
--------------------------------
### Displaying testrunner.tcl Help
Source: https://github.com/dolthub/doltlite/blob/master/doc/testrunner.md
This command displays a summary of all available command-line options for the testrunner.tcl script.
```shell
test/testrunner.tcl help
```
--------------------------------
### Get Diff Statistics Between Branches
Source: https://github.com/dolthub/doltlite/blob/master/doc/doltlite/demo.md
Use `dolt_diff_stat` to get a summary of table differences (rows added, deleted, modified) between two branches.
```sql
SELECT table_name, rows_added, rows_deleted, rows_modified
FROM dolt_diff_stat('theory/butler', 'theory/ficus');
```
--------------------------------
### Initiate WASM Module Loading and Rendering
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/module-symbols.html
Calls the sqlite3InitModule factory function with the defined module configuration and then calls renderIt once the module is loaded.
```javascript
self.sqlite3InitModule(myModule).then(renderIt);
})();
```
--------------------------------
### Example of %type and %destructor directives
Source: https://github.com/dolthub/doltlite/blob/master/doc/lemon.html
This example demonstrates how to define a data type for a non-terminal and specify a destructor to free allocated memory, preventing memory leaks.
```lemon
%type nt {void*}
%destructor nt { free($$); }
nt(A) ::= ID NUM. { A = malloc( 100 ); }
```
--------------------------------
### Build SQLite with ZLIB
Source: https://github.com/dolthub/doltlite/blob/master/doc/compile-for-windows.md
Run this command to build the SQLite executable with ZLIB support enabled.
```makefile
make clean sqlite3.exe BUILD_ZLIB=1
```
--------------------------------
### Struct Description JSON Example
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/jaccwabyt/jaccwabyt.md
Example of a JSON object describing a C struct, including its name, size, and member details like offset, size, and signature.
```json
{
"name": "MyStruct",
"sizeof": 16,
"members": {
"member1": {"offset": 0,"sizeof": 4,"signature": "i"},
"member2": {"offset": 4,"sizeof": 4,"signature": "p"},
"member3": {"offset": 8,"sizeof": 8,"signature": "j"}
}
}
```
--------------------------------
### Configure PATH for 32-bit builds
Source: https://github.com/dolthub/doltlite/blob/master/doc/compile-for-windows.md
Prepend the 32-bit TCL binary directory to the system PATH environment variable.
```batch
set PATH=c:\tcl32\bin;%PATH%
```
--------------------------------
### DoltLite Diff Stat
Source: https://github.com/dolthub/doltlite/blob/master/doc/doltlite/demo.md
Get a summary of differences between two references using `dolt_diff_stat`.
```sql
SELECT * FROM dolt_diff_stat('ref1', 'ref2')
```
--------------------------------
### Update Emscripten SDK
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README.md
Commands to update an existing Emscripten SDK installation to the latest version.
```bash
$ git pull
$ ./emsdk install latest
$ ./emsdk activate latest
```
--------------------------------
### Build DoltLite and variants
Source: https://github.com/dolthub/doltlite/blob/master/AGENTS.md
Commands to build the CLI shell, library, or stock SQLite for comparison using the autosetup build system.
```bash
cd build
../configure
make doltlite # CLI shell — the prolly engine (default)
make doltlite-lib # libdoltlite.a + .so/.dylib + doltlite.h
make DOLTLITE_PROLLY=0 sqlite3 # stock SQLite, for oracle/perf comparison
```
--------------------------------
### Verify SQLite TCL Extension Version
Source: https://github.com/dolthub/doltlite/blob/master/doc/tcl-extension-testing.md
Confirm that the installed TCL extension is of the correct version.
```bash
make tclextension-verify
```
--------------------------------
### Build the SQLite deliverable DLL
Source: https://github.com/dolthub/doltlite/blob/master/doc/compile-for-windows.md
Execute nmake with the specified Makefile and compiler options to generate sqlite3.dll and sqlite3.def.
```bash
nmake /f Makefile.msc sqlite3.dll USE_NATIVE_LIBPATHS=1 "OPTS=-DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_GEOPOLY=1 -DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 -DSQLITE_ENABLE_SERIALIZE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS=1"
```
--------------------------------
### Create and Query Vector Tables with vec1
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Demonstrates creating a virtual vector table, training an index, and performing a KNN search with metadata filtering.
```sql
CREATE VIRTUAL TABLE embeddings USING vec1(vector, category);
INSERT INTO embeddings(rowid, vector, category) VALUES (1, :f32blob, 3);
-- Train and build the index (PQ compression; needs >= 512 vectors)
SELECT vec1_train(vector, '{nbucket: 64, codesize: 8, distance: "cos"}')
FROM embeddings_base; -- returns a model blob
INSERT INTO embeddings(cmd, arg) VALUES ('rebuild', :model);
-- KNN with metadata filtering and exact reranking
SELECT rowid FROM embeddings(:query, '{k: 100}')
WHERE category = 3
ORDER BY vec1_cos_distance(:query, vector) LIMIT 10;
```
--------------------------------
### Initialize WASMFS with OPFS
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/speedtest1.html
Initializes WASMFS with OPFS if available. Returns the mount directory or an empty string if not supported or initialization fails. This function is memoized.
```javascript
const wasmfsDir = function f(wasmUtil){
if(undefined !== f._) return f._;
const pdir = '/persistent';
if( !self.FileSystemHandle || !self.FileSystemDirectoryHandle || !self.FileSystemFileHandle){
return f._ = "";
}
try{
if(0===wasmUtil.xCallWrapped( 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], pdir )){
return f._ = pdir;
}else{
return f._ = "";
}
}catch(e){
// sqlite3_wasm_init_wasmfs() is not available
return f._ = "";
}
};
wasmfsDir._ = undefined;
```
--------------------------------
### Serve WASM Module Remotely
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/README.md
Command to start the althttpd server with SharedArrayBuffer enabled on the remote machine.
```bash
althttpd --enable-sab --port 8080 --popup
```
--------------------------------
### Build WebAssembly Version
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Commands to build the WebAssembly version of DoltLite.
```bash
./configure
make sqlite3.c sqlite3.h sqlite3ext.h
make -C ext/wasm
# → ext/wasm/jswasm/{sqlite3.js,sqlite3.mjs,sqlite3.wasm}
make -C ext/wasm DOLTLITE_WASM=0 # upstream SQLite wasm instead
make -C ext/wasm DOLTLITE_ENABLE_REMOTES=0 # DoltLite without remote clients
make -C ext/wasm dist # zip package
```
--------------------------------
### C Struct Definition
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/jaccwabyt/jaccwabyt.md
Example C struct definition for 'Foo' with integer, pointer, and 64-bit integer members.
```c
// C-side:
struct Foo {
int member1;
void * member2;
int64_t member3;
};
```
--------------------------------
### Build Stock SQLite
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Command to build standard SQLite instead of DoltLite.
```bash
make DOLTLITE_PROLLY=0 sqlite3
```
--------------------------------
### Advanced struct instantiation with options
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/jaccwabyt/jaccwabyt.md
Create a struct instance with advanced options including wrapping a pointer, taking ownership, zeroing on dispose, and allocating extra bytes.
```javascript
const x = new MyStruct({
wrap: ptr,
takeOwnership: bool,
zeroOnDispose: bool ,
extraBytes: int
});
```
--------------------------------
### Configure SQLite Extension (Unix)
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/tea/README.txt
Configure the SQLite extension build on Unix-like systems. Specify the Tcl installation root directory.
```bash
./configure --with-tcl=/path/to/tcl/install/root
```
--------------------------------
### Initialize and Run SQLTester Worker
Source: https://github.com/dolthub/doltlite/blob/master/ext/wasm/SQLTester/index.html
Sets up a Web Worker to run SQLTester tests, handles messages from the worker, and initiates test execution. Includes logging and error handling for worker loading.
```javascript
(async function(){
const W = new Worker('SQLTester.run.mjs',{ type: 'module' });
const wPost = (type,payload)=>W.postMessage({type,payload});
const mapToString = (v)=>{
switch(typeof v){
case 'string': return v;
case 'number':
case 'boolean':
case 'undefined':
case 'bigint': return ''+v;
default: break;
}
if(null===v) return 'null';
if(v instanceof Error){
v = { message: v.message, stack: v.stack, errorClass: v.name };
}
return JSON.stringify(v,undefined,2);
};
const normalizeArgs = (args)=>args.map(mapToString);
const logTarget = document.querySelector('#test-output');
const logClass = function(cssClass,...args){
const ln = document.createElement('div');
if(cssClass){
for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
ln.classList.add(c);
}
}
ln.append(document.createTextNode(normalizeArgs(args).join(' ')));
logTarget.append(ln);
};
{
const cbReverse = document.querySelector('#cb-log-reverse');
const cbReverseKey = 'SQLTester:cb-log-reverse';
const cbReverseIt = ()=>{
logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
};
cbReverse.addEventListener('change', cbReverseIt, true);
cbReverseIt();
}
const btnRun = document.querySelector('#btn-run-tests');
const runTests = ()=>{
btnRun.setAttribute('disabled','disabled');
wPost('run-tests');
logTarget.innerText = 'Running tests...';
}
btnRun.addEventListener('click', runTests);
const log2 = function f(...args){ logClass('', ...args); return f; };
const log = function f(...args){ logClass('','index.html:',...args); return f; };
const timerId = setTimeout( ()=>{
logClass('error',"The SQLTester module is taking an unusually ", "long time to load. More information may be available", "in the dev console.");
}, 3000 /* assuming localhost */ );
W.onmessage = function({data}){
switch(data.type){
case 'stdout':
log2(data.payload.message);
break;
case 'tests-end':
btnRun.removeAttribute('disabled');
delete data.payload.nTest;
log("test results:",data.payload);
break;
case 'is-ready':
clearTimeout(timerId);
runTests();
break;
default:
log("unhandled onmessage",data);
break;
}
};
})();
```
--------------------------------
### Get Environment Variable
Source: https://github.com/dolthub/doltlite/blob/master/autosetup/README.md
Fetches an environment variable from a KEY=VALUE pair passed to the configure script or from system environment variables. It is not the same as `getenv`.
```tcl
get-env VAR ?default?
```
--------------------------------
### Hello World SQLite3 Database Connection
Source: https://github.com/dolthub/doltlite/blob/master/ext/jni/README.md
Demonstrates opening an in-memory SQLite3 database using the JNI binding. Ensure databases are always closed using sqlite3_close_v2() after use, and all active statements are finalized.
```java
import org.sqlite.jni.*;
import static org.sqlite.jni.CApi.*;
...
final sqlite3 db = sqlite3_open(":memory:");
try {
final int rc = sqlite3_errcode(db);
if( 0 != rc ){
if( null != db ){
System.out.print("Error opening db: "+sqlite3_errmsg(db));
}else{
System.out.print("Error opening db: rc="+rc);
}
... handle error ...
}
// ... else use the db ...
}finally{
// ALWAYS close databases using sqlite3_close() or sqlite3_close_v2()
// when done with them. All of their active statement handles must
// first have been passed to sqlite3_finalize().
sqlite3_close_v2(db);
}
```
--------------------------------
### Build DoltLite on Windows
Source: https://github.com/dolthub/doltlite/blob/master/README.md
Build sequence for Windows using MSYS2/MINGW64 environment.
```bash
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-zlib make tcl
mkdir -p build && cd build
../configure
make doltlite.exe
./doltlite.exe :memory:
```
--------------------------------
### Configure SQLite with optimized CFLAGS
Source: https://github.com/dolthub/doltlite/blob/master/autoconf/README.txt
Example of overriding the default CFLAGS during configuration to produce smaller binaries by using the -Os optimization flag.
```bash
$ CFLAGS="-Os" ./configure
```
--------------------------------
### Configure SQLite Build with Script
Source: https://github.com/dolthub/doltlite/blob/master/autosetup/README.md
Defines all configure flags for known build modes, executes a provided script for build-mode-specific configuration, and then runs common finalization steps.
```shell
sqlite-configure BUILD-NAME {script}
```