Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanShang committed Jun 25, 2024
1 parent 32d9660 commit 419ac5b
Show file tree
Hide file tree
Showing 24 changed files with 24,390 additions and 76 deletions.
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ if (EMSCRIPTEN)
endif()

add_subdirectory(kuzu)

include_directories(lib)

add_executable(kuzu-wasm lib/web_bind.cpp lib/web_database.cpp lib/web_connection.cpp lib/web_prepared_statement.cpp lib/web_query_result.cpp)

target_link_libraries(kuzu-wasm kuzu)

# Release build
Expand Down Expand Up @@ -66,7 +63,7 @@ set_target_properties(
-s MODULARIZE=1 -s EXPORT_NAME='Kuzu' -s EXPORT_ES6=1 \
-sNO_DISABLE_EXCEPTION_CATCHING \
--embed-file ../../kuzu/dataset/demo-db/ \
-s EXPORTED_RUNTIME_METHODS='[\"ccall\", \"stackSave\", \"stackAlloc\", \"stackRestore\",\"FS\"]' \
-s EXPORTED_RUNTIME_METHODS='[\"ccall\", \"stackSave\", \"stackAlloc\", \"stackRestore\",\"FS\",\"UTF8ToString\"]' \
")

# --emit-tsd 'interface.d.ts' \
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024-2025 Dylan Shang.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 26 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
.DEFAULT_GOAL := help

SOURCE_FILES := $(wildcard *.cpp) $(wildcard *.h)

.PHONY: check_environment
check_environment:
check_environment: ## check_environment
@echo "emcc from: `which emcc`"
@echo "emcmake from: `which emcmake`"
@echo "emcmake from: `which npm`"

.PHONY: wasm_dev
wasm_dev: check_environment ## Compile kuzu-wasm in development mode
wasm_dev_target = build/dev/kuzu-wasm.wasm
$(wasm_dev_target): $(SOURCE_FILES)
./scripts/build_wasm.sh dev
wasm_dev: $(wasm_dev_target) ## Compile kuzu-wasm in development mode

.PHONY: wasm_relsize
wasm_relsize: check_environment ## Compile kuzu-wasm in relsize mode
.PHONY: wasm_relsize
wasm_relsize_target := build/relsize/kuzu-wasm.wasm
$(wasm_relsize_target): $(SOURCE_FILES)
./scripts/build_wasm.sh relsize
wasm_relsize: $(wasm_relsize_target) ## Compile kuzu-wasm in development mode

.PHONY: wasm_relperf
wasm_relperf: check_environment ## Compile kuzu-wasm in relperf mode
wasm_relperf_target := build/relperf/kuzu-wasm.wasm
$(wasm_relperf_target): $(SOURCE_FILES)
./scripts/build_wasm.sh relperf
wasm_relperf: $(wasm_relperf_target) ## Compile kuzu-wasm in relperf mode

# wasm_package = $(packages/kuzu-wasm/src/kuzu-wasm.wasm, \
# packages/kuzu-wasm/src/kuzu-wasm.js, \
# packages/kuzu-wasm/src/kuzu-wasm.worker.mjs)
.PHONY: wasm_package
wasm_package: wasm_relperf ## Package kuzu-wasm
mkdir -p packages/kuzu-wasm/src
.PHONY: package
package: $(wasm_relperf_target) ## Package kuzu-wasm
cp build/relperf/kuzu-wasm.* packages/kuzu-wasm/src/
yarn workspace @kuzu/kuzu-wasm build:debug

.PHONY: package_dev
package_dev: $(wasm_dev_target) ## Package kuzu-wasm in dev mode
cp build/dev/kuzu-wasm.* packages/kuzu-wasm/src/
yarn workspace @kuzu/kuzu-wasm build:release

.PHONY: shell
shell: wasm_package ## Build kuzu-shell application
shell: package ## Build kuzu-shell application
yarn
yarn install
yarn workspace @kuzu/kuzu-shell build:release

.PHONY: shell-dev
shell-dev: ## Start kuzu-shell in development mode
.PHONY: shell_dev
shell_dev: package_dev ## Start kuzu-shell in development mode
yarn workspace @kuzu/kuzu-shell start

dev: ## Start kuzu-shell in development mode
dev: ## use kuzu_dev in plain html
./scripts/run.sh

.PHONY: clean
Expand Down
69 changes: 32 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
# kuzu-wasm
<div align="center">
<img src="https://raw.githubusercontent.com/dylanshang/kuzu-wasm/main/logo/logo.png" height="100">
<h1>Kùzu-Wasm</h1>
</div>

Make sure you have installed:
1. Python3
2. [Emscripten](https://emscripten.org/docs/getting_started/downloads.html)
<div align="center">
<a href="https://www.npmjs.com/package/@kuzu/kuzu-wasm/v/latest">
<img src="https://img.shields.io/npm/v/@kuzu/kuzu-wasm?logo=npm" alt="kuzu-wasm package on NPM">
</a>
<a href="https://github.com/dylanshang/kuzu-wasm/actions">
<img src="https://github.com/dylanshang/kuzu-wasm/actions/workflows/shell.yml/badge.svg?branch=main" alt="Github Actions Badge">
</a>
<a href="https://discord.gg/VtX2gw9Rug" rel="nofollow">
<img src="https://camo.githubusercontent.com/4c014897742bfc8910e0e2eefaf357f8b6957dca8179a6c8106b5189041cd8b9/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f313139363531303131363338383830363833373f6c6f676f3d646973636f7264" alt="discord" data-canonical-src="https://img.shields.io/discord/1196510116388806837?logo=discord" style="max-width: 100%;"></a>
</div>
<h1></h1>

## Download kuzu
So far, `v0.4.2` is the latest release version of kuzu.
For development consistency, I recommend that everyone use the same version
```
cd kuzu-wasm
git submodule update --init
```
Or you can download recursively
```
git clone git@github.com:DylanShang/kuzu-wasm.git --recursive
```
[Kùzu](https://github.com/kuzudb/kuzu) is an embedded graph database built for query speed and scalability.

## Build command
```
chmod 755 build.sh
./build.sh
```
## Run command
```
chmod 755 run.sh
./run.sh
```
## Update kuzu
```
git submodule update --remote
```
Kùzu-Wasm brings kuzu to every browser thanks to WebAssembly.

## Simple test
```
var database = new Module.WebDatabase("test",0,4,false,false,4194304*16)
var connection = new Module.WebConnection(database,0)
var r = connection.query("CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))")
r.toString()
r.isSuccess()
var r2 = connection.query('COPY User From "kuzu/dataset/demo-db/csv/user.csv"')

Try it out at [kuzu-shell.netlify.app](https://kuzu-shell.netlify.app), and chat with us on [Discord](https://discord.com/invite/VtX2gw9Rug).

## Build from source
```shell
git clone https://github.com/DylanShang/kuzu-wasm.git --recursive
make wasm_dev
```

## Repository Structure

| Subproject | Description | Language |
| -------------------------------------------------------- | :------------- | :--------- |
| [kuzu_wasm](/lib) | Wasm Library | C++ |
| [@kuzu/kuzu-wasm](/packages/kuzu-wasm) | Javascript API | Javascript |
| [@kuzu/kuzu-shell](/packages/kuzu-shell) | Cypher Shell | React |

## Debug
I debug using Chrome DevTools as described in this [blog post](https://developer.chrome.com/blog/wasm-debugging-2020/), which takes a few steps to set up. The first is to install the [C/C++ DevTools Support Extension](https://chrome.google.com/webstore/detail/cc%20%20-devtools-support-dwa/pdcpmagijalfljmkmjngeonclgbbannb) and to enable **WebAssembly Debugging: Enable DWARF support** in the DevTools settings.
8 changes: 8 additions & 0 deletions lib/include/web_query_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ class WebQueryResult {

std::string printExecutionResult();

double getArrowSchema();

double getArrowChunk();

private:
std::unique_ptr<QueryResult> queryResult;

std::unique_ptr<ArrowSchema> resultSchema;

std::unique_ptr<ArrowArray> resultArray;
};
12 changes: 9 additions & 3 deletions lib/web_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace kuzu::main;

int main(){return 0;}


EMSCRIPTEN_BINDINGS(WebDatabase) {
class_<WebDatabase>("WebDatabase")
.constructor<const std::string&, uint64_t, uint64_t, bool, bool, uint64_t>()
Expand All @@ -25,10 +26,10 @@ EMSCRIPTEN_BINDINGS(WebConnection) {
.function("setMaxNumThreadForExec", &WebConnection::setMaxNumThreadForExec)
.function("getNumNodes", &WebConnection::getNumNodes)
.function("getNumRels", &WebConnection::getNumRels)
.function("query", &WebConnection::query)
.function("execute", &WebConnection::execute,allow_raw_pointers());
.function("query", &WebConnection::query);
// .function("prepare", &WebConnection::prepare)
// .function("execute", &WebConnection::execute,allow_raw_pointers());
}
// .function("prepare", &WebConnection::prepare)

EMSCRIPTEN_BINDINGS(WebPreparedStatement) {
class_<WebPreparedStatement>("WebPreparedStatement")
Expand All @@ -51,7 +52,12 @@ EMSCRIPTEN_BINDINGS(WebQueryResult) {
.function("getCompilingTime", &WebQueryResult::getCompilingTime)
.function("toString", &WebQueryResult::toString)
.function("printExecutionResult", &WebQueryResult::printExecutionResult)
.function("getArrowChunk", &WebQueryResult::getArrowChunk)
.function("getArrowSchema", &WebQueryResult::getArrowSchema)
.function("getNumTuples", &WebQueryResult::getNumTuples);
// .function("getNext", &WebQueryResult::getNext)

}


// register_vector<std::string>("VectorString");
10 changes: 10 additions & 0 deletions lib/web_query_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ size_t WebQueryResult::getNumTuples() {
return queryResult->getNumTuples();
}

double WebQueryResult::getArrowSchema(){
resultSchema = queryResult->getArrowSchema();
return reinterpret_cast<uintptr_t>(resultSchema.get());
}

double WebQueryResult::getArrowChunk(){
int64_t chunkSize = getNumTuples();
resultArray = queryResult->getNextArrowChunk(chunkSize);
return reinterpret_cast<uintptr_t>(resultArray.get());
}

std::string WebQueryResult::printExecutionResult() {

Expand Down
Binary file added logo/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions logo/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 419ac5b

Please sign in to comment.