Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ atlassian-ide-plugin.xml
*.class
.fleet/settings.json
keys
.claude
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</p>


This is a port of the awesome [xerial/sqlite-jdbc](https://github.com/xerial/sqlite-jdbc/) to run in pure Java with SQLite compiled to WASM thanks to [Chicory](https://github.com/dylibso/chicory).
This is a port of the awesome [xerial/sqlite-jdbc](https://github.com/xerial/sqlite-jdbc/) to run in pure Java with SQLite compiled to WASM thanks to [Endive](https://github.com/bytecodealliance/endive).

## Why?

Expand All @@ -30,7 +30,7 @@ Among the main reasons:
There are a few steps to achieve the result:

- compile SQLite to [WebAssembly](https://webassembly.org/)
- translate the SQLite payload to pure Java bytecode using [Chicory Compiler](https://chicory.dev/docs/usage/build-time-compiler)
- translate the SQLite payload to pure Java bytecode using [Endive Compiler](https://endive.run/docs/usage/build-time-compiler)
- run SQLite similarly to how it's done using JNI in the original JDBC dirver, but all in pure Java
- ship an extremely small and self contained `jar` that can run wherever the JVM can go!

Expand Down Expand Up @@ -181,4 +181,4 @@ This project is building on the shoulders of giants. Special thanks to:

- [xerial/sqlite-jdbc](https://github.com/xerial/sqlite-jdbc/) – the original JDBC driver
- [ncruces/go-sqlite3](https://github.com/ncruces/go-sqlite3) – for prior work and invaluable help
- [dylibso/chicory](https://github.com/dylibso/chicory) – for the Wasm compiler to Java Bytecode
- [bytecodealliance/endive](https://github.com/bytecodealliance/endive) – for the Wasm compiler to Java Bytecode
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<artifactId>sqlite4j</artifactId>
<version>9.9.9.9-SNAPSHOT</version>
<name>Pure Java SQLite JDBC Driver</name>
<description>SQLite JDBC library running in Wasm thanks to Chicory</description>
<description>SQLite JDBC library running in Wasm thanks to Endive</description>
<url>https://github.com/roastedroot/sqlite4j</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.14.4</junit.version>
<surefire.version>3.5.6</surefire.version>
<chicory.version>1.7.5</chicory.version>
<endive.version>1.0.0</endive.version>
</properties>

<licenses>
Expand Down Expand Up @@ -87,7 +87,7 @@
<annotationProcessorPathsUseDepMgmt>true</annotationProcessorPathsUseDepMgmt>
<annotationProcessorPaths>
<path>
<groupId>com.dylibso.chicory</groupId>
<groupId>run.endive</groupId>
<artifactId>annotations-processor</artifactId>
</path>
</annotationProcessorPaths>
Expand Down Expand Up @@ -151,9 +151,9 @@
</plugin>

<plugin>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory-compiler-maven-plugin</artifactId>
<version>${chicory.version}</version>
<groupId>run.endive</groupId>
<artifactId>endive-compiler-maven-plugin</artifactId>
<version>${endive.version}</version>
<executions>
<execution>
<id>compile-sqlite</id>
Expand Down Expand Up @@ -281,9 +281,9 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<groupId>run.endive</groupId>
<artifactId>bom</artifactId>
<version>${chicory.version}</version>
<version>${endive.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -293,19 +293,19 @@
<dependencies>
<!-- WASM dependencies -->
<dependency>
<groupId>com.dylibso.chicory</groupId>
<groupId>run.endive</groupId>
<artifactId>wasm</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<groupId>run.endive</groupId>
<artifactId>runtime</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<groupId>run.endive</groupId>
<artifactId>wasi</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<groupId>run.endive</groupId>
<artifactId>annotations</artifactId>
</dependency>

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/roastedroot/sqlite4j/core/WasmDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
import static io.roastedroot.sqlite4j.core.wasm.WasmDBExports.SQLITE_SERIALIZE_NOCOPY;
import static io.roastedroot.sqlite4j.core.wasm.WasmDBExports.SQLITE_UTF8;

import com.dylibso.chicory.runtime.ByteArrayMemory;
import com.dylibso.chicory.runtime.ImportValues;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.runtime.Memory;
import com.dylibso.chicory.wasi.WasiOptions;
import com.dylibso.chicory.wasi.WasiPreview1;
import com.dylibso.chicory.wasm.WasmModule;
import com.dylibso.chicory.wasm.types.MemoryLimits;
import io.roastedroot.sqlite4j.BusyHandler;
import io.roastedroot.sqlite4j.Collation;
import io.roastedroot.sqlite4j.Function;
Expand Down Expand Up @@ -38,6 +30,14 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.sql.SQLException;
import run.endive.runtime.ByteArrayMemory;
import run.endive.runtime.ImportValues;
import run.endive.runtime.Instance;
import run.endive.runtime.Memory;
import run.endive.wasi.WasiOptions;
import run.endive.wasi.WasiPreview1;
import run.endive.wasm.WasmModule;
import run.endive.wasm.types.MemoryLimits;

public class WasmDB extends DB implements WasmDBImports {
public static final int PTR_SIZE = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static io.roastedroot.sqlite4j.core.Codes.SQLITE_NULL;

import com.dylibso.chicory.runtime.ExportFunction;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.wasm.types.Value;
import java.nio.charset.StandardCharsets;
import run.endive.runtime.ExportFunction;
import run.endive.runtime.Instance;
import run.endive.wasm.types.Value;

// Manually writing it to avoid passing through the Map lookup on every invocation
public class WasmDBExports {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.roastedroot.sqlite4j.core.wasm;

import com.dylibso.chicory.runtime.HostFunction;
import com.dylibso.chicory.wasm.types.ValueType;
import java.util.List;
import run.endive.runtime.HostFunction;
import run.endive.wasm.types.ValueType;

public interface WasmDBImports {

Expand Down
8 changes: 4 additions & 4 deletions wasm-lib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Download the latest SQLite amalgamation 3.48.0 as of today
# rm -rf sqlite-amalgamation
# wget https://www.sqlite.org/2026/sqlite-amalgamation-3530100.zip
# unzip sqlite-amalgamation-3530100.zip
# mv sqlite-amalgamation-3530100 sqlite-amalgamation
# rm sqlite-amalgamation-3530100.zip
# wget https://www.sqlite.org/2026/sqlite-amalgamation-3530300.zip
# unzip sqlite-amalgamation-3530300.zip
# mv sqlite-amalgamation-3530300 sqlite-amalgamation
# rm sqlite-amalgamation-3530300.zip

# Download and install Binaryen for optimizations
# rm -rf binaryen
Expand Down
Binary file modified wasm-lib/libsqlite3.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions wasm-lib/prepare-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ mv wasi-sdk-25.0-x86_64-linux wasi-sdk
rm wasi-sdk-25.0-x86_64-linux.tar.gz

rm -rf sqlite-amalgamation
wget https://www.sqlite.org/2026/sqlite-amalgamation-3530100.zip
unzip sqlite-amalgamation-3530100.zip
mv sqlite-amalgamation-3530100 sqlite-amalgamation
rm sqlite-amalgamation-3530100.zip
wget https://www.sqlite.org/2026/sqlite-amalgamation-3530300.zip
unzip sqlite-amalgamation-3530300.zip
mv sqlite-amalgamation-3530300 sqlite-amalgamation
rm sqlite-amalgamation-3530300.zip

rm -rf binaryen
wget https://github.com/WebAssembly/binaryen/releases/download/version_121/binaryen-version_121-x86_64-linux.tar.gz
Expand Down
Loading