picovolt 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +162 -0
- package/package.json +30 -0
- package/picovolt.d.ts +35 -0
- package/picovolt.js +9 -0
- package/picovolt_bg.js +248 -0
- package/picovolt_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 Derivative
|
|
95
|
+
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 2026 PicoVolt Authors
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# PicoVolt (PVDB)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/MiniJe/picovolt/actions/workflows/ci.yml)
|
|
4
|
+
[](CHANGELOG.md)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
PicoVolt is an embedded database engine written from scratch in Rust. It is
|
|
9
|
+
experimental software. It has not been audited or hardened for production, so use
|
|
10
|
+
it to learn from and prototype with rather than to store data you cannot lose.
|
|
11
|
+
|
|
12
|
+
The engine decouples query logic from storage representation through a
|
|
13
|
+
Virtualization Layer Engine (VLE) that shifts between two on-disk shapes:
|
|
14
|
+
|
|
15
|
+
- **Development mode:** a `.pv/` workspace of mutable, append-only chunk files
|
|
16
|
+
plus a content-addressed blob store, friendly to git and code review.
|
|
17
|
+
- **Production mode:** a single contiguous, memory-mappable `.pvdb` file produced
|
|
18
|
+
by `pv_bake()`.
|
|
19
|
+
|
|
20
|
+
Pages are chameleon. Hot data lands in a slotted row layout for O(1) appends, and
|
|
21
|
+
idle pages can be transposed into a packed columnar layout for compression and
|
|
22
|
+
cache efficiency.
|
|
23
|
+
|
|
24
|
+
## Status
|
|
25
|
+
|
|
26
|
+
The engine is built out across four phases, all implemented, with 103 unit and
|
|
27
|
+
integration tests plus doctests passing and a clean `cargo clippy -D warnings` on
|
|
28
|
+
Linux and Windows. Changes are tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
29
|
+
|
|
30
|
+
| Phase | Scope | Status |
|
|
31
|
+
|-------|-------|--------|
|
|
32
|
+
| 1 | Core memory layouts and error taxonomy | Done |
|
|
33
|
+
| 2 | Page engine, CAS dedup, compression, VLE router | Done |
|
|
34
|
+
| 3 | MVCC and snapshot isolation, WASM runtime | Done |
|
|
35
|
+
| 4 | Public surface (`pv_open_dev` / `pv_open_prod` / `query` / `pv_bake`) | Done |
|
|
36
|
+
|
|
37
|
+
### Module map
|
|
38
|
+
|
|
39
|
+
| Module | Responsibility |
|
|
40
|
+
|--------|----------------|
|
|
41
|
+
| [`core/types.rs`](src/core/types.rs) | constants, ids, `PageType`, `RecordEnvelope`, page and file headers (explicit little-endian codecs) |
|
|
42
|
+
| [`core/errors.rs`](src/core/errors.rs) | unified `PvError` and `ComplianceError` |
|
|
43
|
+
| [`core/value.rs`](src/core/value.rs) | dynamically-typed `Value` and `Row` |
|
|
44
|
+
| [`storage/page.rs`](src/storage/page.rs) | slotted row page (O(1) append), chain links, columnar transposition |
|
|
45
|
+
| [`storage/cache.rs`](src/storage/cache.rs) | bounded LRU buffer pool (enables larger-than-RAM reads) |
|
|
46
|
+
| [`storage/cas.rs`](src/storage/cas.rs) | BLAKE3 content-addressable dedup (memory, dev-files, mmap) |
|
|
47
|
+
| [`storage/compress.rs`](src/storage/compress.rs) | Delta-Z, LEB128 varints, dictionary bit-packing |
|
|
48
|
+
| [`storage/index.rs`](src/storage/index.rs) | in-memory ordered secondary index (value to record addresses; point and range) |
|
|
49
|
+
| [`storage/record.rs`](src/storage/record.rs) | row and record-body serialization with CAS interception |
|
|
50
|
+
| [`storage/vle.rs`](src/storage/vle.rs) | dev directory store, prod mmap monolith, `bake` |
|
|
51
|
+
| [`engine/mvcc.rs`](src/engine/mvcc.rs) | transaction clock and snapshot visibility |
|
|
52
|
+
| [`engine/wasm.rs`](src/engine/wasm.rs) | sandboxed `wasmi` extension runtime and the `WasmExec` backend trait |
|
|
53
|
+
| [`engine/interp.rs`](src/engine/interp.rs) | `pv-wasm`: a from-scratch WASM interpreter (integer subset) |
|
|
54
|
+
| [`engine/query.rs`](src/engine/query.rs) | SQL front-end (CREATE/INSERT/UPDATE/DELETE/DROP, `SELECT` with projection and aggregates, `WHERE` predicates, `BEFORE`, `ORDER BY`, `LIMIT`) |
|
|
55
|
+
| [`engine/compliance.rs`](src/engine/compliance.rs) | optional, app-driven usage-policy hook (not a license requirement) |
|
|
56
|
+
| [`db.rs`](src/db.rs) | the `Database` surface that ties it together |
|
|
57
|
+
|
|
58
|
+
### Engineering notes
|
|
59
|
+
|
|
60
|
+
- **Explicit little-endian codecs** for every on-disk structure, instead of
|
|
61
|
+
casting `#[repr(C)]` structs, so the file format stays portable and its byte
|
|
62
|
+
offsets are exact.
|
|
63
|
+
- **Two interchangeable WASM backends.** The default is the `wasmi` interpreter
|
|
64
|
+
(vetted, full WASM). Alongside it, `pv-wasm`
|
|
65
|
+
([`engine/interp.rs`](src/engine/interp.rs)) is a from-scratch interpreter: a
|
|
66
|
+
hand-written binary decoder and structured-control stack machine covering the
|
|
67
|
+
`i32` and `i64` integer subset. Both implement the `WasmExec` trait, and a
|
|
68
|
+
differential test checks `pv-wasm` against `wasmi` to keep it honest. Floats,
|
|
69
|
+
tables, globals, imports, SIMD, and `br_table` are out of scope for `pv-wasm`
|
|
70
|
+
and are rejected rather than mis-run.
|
|
71
|
+
- **Page-backed engine.** Tables are append-only chains of row pages, each header
|
|
72
|
+
linking to the next. Inserts append to a tail page and write only that page
|
|
73
|
+
plus an O(tables) manifest, so autocommit is O(1) per insert rather than a
|
|
74
|
+
whole-table rewrite. Reads stream through a bounded buffer pool
|
|
75
|
+
([`storage/cache.rs`](src/storage/cache.rs)), so datasets need not fit in RAM,
|
|
76
|
+
and opt-in ordered indexes ([`storage/index.rs`](src/storage/index.rs)) turn
|
|
77
|
+
`WHERE col = value` into a point lookup and range comparisons such as
|
|
78
|
+
`WHERE col > v` into an ordered scan rather than a full scan.
|
|
79
|
+
- **Selectable durability.** `Database::set_durability(Durability::Sync)` makes
|
|
80
|
+
each flush `fsync` the data and commit the manifest atomically (write to a temp
|
|
81
|
+
file, `fsync`, then rename). The default `Fast` mode uses the OS cache only:
|
|
82
|
+
fast and durable on a clean exit, but not power-loss-safe.
|
|
83
|
+
- **Hardened against untrusted input.** Opening a `.pvdb` or workspace, or running
|
|
84
|
+
a WASM module, validates manifest hashes (no path traversal), bounds-checks CAS
|
|
85
|
+
offsets and page chains (no out-of-bounds reads or infinite loops on a crafted
|
|
86
|
+
file), and caps WASM resource counts. The decoders are fuzzed (a cross-platform
|
|
87
|
+
fuzz-lite test and a [`fuzz/`](fuzz) cargo-fuzz crate), and `cargo audit`
|
|
88
|
+
reports no advisories. Both run in CI. See [SECURITY.md](SECURITY.md).
|
|
89
|
+
|
|
90
|
+
## Build
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
cargo build
|
|
94
|
+
cargo test
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Examples and benchmarks
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
cargo run --release --example notes # a small notes app: CRUD, edit history,
|
|
101
|
+
# time-travel, CAS dedup, publish (bake)
|
|
102
|
+
cargo run --release --example repl # interactive SQL shell (pvsql)
|
|
103
|
+
cargo run --release --example bench # evaluation harness across modes and workloads
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
SQL supported: `CREATE TABLE`, `CREATE INDEX ON t (col)`, `INSERT`,
|
|
107
|
+
`UPDATE ... SET ... WHERE`, `DELETE ... WHERE`, `DROP TABLE`, and
|
|
108
|
+
`SELECT {* | col, ... | COUNT/SUM/MIN/MAX/AVG(...)} FROM t [WHERE <pred>]
|
|
109
|
+
[GROUP BY cols] [BEFORE tx] [ORDER BY col [ASC|DESC]] [LIMIT n]`, where `<pred>`
|
|
110
|
+
combines `col <op> value` (`=`, `!=`, `<`, `<=`, `>`, `>=`, `LIKE`) with `AND`,
|
|
111
|
+
`OR`, and parentheses.
|
|
112
|
+
Durability is selectable via `Database::set_durability` (`Fast` OS-cache default,
|
|
113
|
+
or crash-safe `Sync` with fsync and an atomic manifest).
|
|
114
|
+
|
|
115
|
+
Measured results and the methodology are in [BENCHMARKS.md](BENCHMARKS.md). In
|
|
116
|
+
short, PicoVolt is a page-backed engine with O(1) durable appends (autocommit
|
|
117
|
+
around 33k rows/s, linear), larger-than-RAM reads through a bounded buffer pool (a
|
|
118
|
+
667-page dataset serves from a 16-page pool), ordered secondary indexes (point
|
|
119
|
+
lookups roughly 11,000 times faster than a scan, plus range predicates), MVCC
|
|
120
|
+
time-travel, opt-in crash-safe durability (`Durability::Sync`), and a fast
|
|
121
|
+
compile-and-publish path (CAS dedup, columnar compression, single-file mmap
|
|
122
|
+
artifacts). Current limits: indexes are in-memory (rebuilt on open) and there is
|
|
123
|
+
no concurrency.
|
|
124
|
+
|
|
125
|
+
## Install and distribution
|
|
126
|
+
|
|
127
|
+
| Target | How |
|
|
128
|
+
|--------|-----|
|
|
129
|
+
| **Rust** (crates.io) | `cargo add picovolt` (once published) |
|
|
130
|
+
| **JavaScript / npm** (WebAssembly, browser and Node) | `wasm-pack build --target bundler --release -- --features wasm` |
|
|
131
|
+
| **In-memory** (native, no filesystem) | `Database::open_memory()`, export with `bake_to_bytes()` |
|
|
132
|
+
|
|
133
|
+
PicoVolt runs in the browser through its in-memory backend. Build the WebAssembly
|
|
134
|
+
package with the command above, then `import { Db } from "picovolt"` and run SQL
|
|
135
|
+
with `db.query(...)`. See [src/wasm_api.rs](src/wasm_api.rs) for the JavaScript
|
|
136
|
+
surface.
|
|
137
|
+
|
|
138
|
+
## Extending PicoVolt
|
|
139
|
+
|
|
140
|
+
There are two extension paths: sandboxed WebAssembly user-defined functions, and
|
|
141
|
+
native modules built on the public API. Both are documented in
|
|
142
|
+
[docs/EXTENDING.md](docs/EXTENDING.md).
|
|
143
|
+
|
|
144
|
+
## Project
|
|
145
|
+
|
|
146
|
+
| | |
|
|
147
|
+
|--|--|
|
|
148
|
+
| Roadmap | [ROADMAP.md](ROADMAP.md) |
|
|
149
|
+
| Contributing | [CONTRIBUTING.md](CONTRIBUTING.md) |
|
|
150
|
+
| Code of conduct | [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) |
|
|
151
|
+
| Changelog | [CHANGELOG.md](CHANGELOG.md) |
|
|
152
|
+
| Security policy | [SECURITY.md](SECURITY.md) |
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
Licensed under the [Apache License, Version 2.0](LICENSE). Third-party
|
|
157
|
+
dependencies are under MIT or Apache-2.0 licenses, and their notices apply to
|
|
158
|
+
redistributions (see [`NOTICE`](NOTICE)).
|
|
159
|
+
|
|
160
|
+
The optional [`compliance`](src/engine/compliance.rs) module is not a license
|
|
161
|
+
requirement. It is an opt-in helper for applications that want to enforce their
|
|
162
|
+
own usage policy. Apache-2.0 places no usage restrictions on PicoVolt itself.
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "picovolt",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "PicoVolt (PVDB): a polymorphic embedded database engine in Rust.",
|
|
5
|
+
"version": "0.3.0",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/MiniJe/picovolt"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"picovolt_bg.wasm",
|
|
13
|
+
"picovolt.js",
|
|
14
|
+
"picovolt_bg.js",
|
|
15
|
+
"picovolt.d.ts"
|
|
16
|
+
],
|
|
17
|
+
"main": "picovolt.js",
|
|
18
|
+
"types": "picovolt.d.ts",
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"./picovolt.js",
|
|
21
|
+
"./snippets/*"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"database",
|
|
25
|
+
"embedded",
|
|
26
|
+
"storage-engine",
|
|
27
|
+
"mvcc",
|
|
28
|
+
"columnar"
|
|
29
|
+
]
|
|
30
|
+
}
|
package/picovolt.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* An in-memory PicoVolt database usable from JavaScript.
|
|
6
|
+
*/
|
|
7
|
+
export class Db {
|
|
8
|
+
free(): void;
|
|
9
|
+
[Symbol.dispose](): void;
|
|
10
|
+
/**
|
|
11
|
+
* The most recently committed transaction id, the upper bound for a
|
|
12
|
+
* `... BEFORE tx` time-travel query.
|
|
13
|
+
*/
|
|
14
|
+
currentTx(): number;
|
|
15
|
+
/**
|
|
16
|
+
* Export the whole database as a `.pvdb` byte image (a `Uint8Array` in JS).
|
|
17
|
+
*/
|
|
18
|
+
export(): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Load a database from a `.pvdb` byte image (e.g. one produced by
|
|
21
|
+
* [`export`](Db::export)). Writable, with full time-travel history intact.
|
|
22
|
+
*/
|
|
23
|
+
static fromBytes(bytes: Uint8Array): Db;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new, empty in-memory database.
|
|
26
|
+
*/
|
|
27
|
+
constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Run one SQL statement. Returns a **JSON string** (call `JSON.parse` in JS):
|
|
30
|
+
* `{"columns":[...],"rows":[[...]]}` for `SELECT`, `{"mutated":n}` for
|
|
31
|
+
* `INSERT`/`UPDATE`/`DELETE`, or `{"done":true}` otherwise. Throws the error
|
|
32
|
+
* message (a string) on failure.
|
|
33
|
+
*/
|
|
34
|
+
query(sql: string): string;
|
|
35
|
+
}
|
package/picovolt.js
ADDED
package/picovolt_bg.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-memory PicoVolt database usable from JavaScript.
|
|
3
|
+
*/
|
|
4
|
+
export class Db {
|
|
5
|
+
static __wrap(ptr) {
|
|
6
|
+
const obj = Object.create(Db.prototype);
|
|
7
|
+
obj.__wbg_ptr = ptr;
|
|
8
|
+
DbFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
__destroy_into_raw() {
|
|
12
|
+
const ptr = this.__wbg_ptr;
|
|
13
|
+
this.__wbg_ptr = 0;
|
|
14
|
+
DbFinalization.unregister(this);
|
|
15
|
+
return ptr;
|
|
16
|
+
}
|
|
17
|
+
free() {
|
|
18
|
+
const ptr = this.__destroy_into_raw();
|
|
19
|
+
wasm.__wbg_db_free(ptr, 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The most recently committed transaction id, the upper bound for a
|
|
23
|
+
* `... BEFORE tx` time-travel query.
|
|
24
|
+
* @returns {number}
|
|
25
|
+
*/
|
|
26
|
+
currentTx() {
|
|
27
|
+
const ret = wasm.db_currentTx(this.__wbg_ptr);
|
|
28
|
+
return ret >>> 0;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Export the whole database as a `.pvdb` byte image (a `Uint8Array` in JS).
|
|
32
|
+
* @returns {Uint8Array}
|
|
33
|
+
*/
|
|
34
|
+
export() {
|
|
35
|
+
const ret = wasm.db_export(this.__wbg_ptr);
|
|
36
|
+
if (ret[3]) {
|
|
37
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
38
|
+
}
|
|
39
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
40
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
41
|
+
return v1;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Load a database from a `.pvdb` byte image (e.g. one produced by
|
|
45
|
+
* [`export`](Db::export)). Writable, with full time-travel history intact.
|
|
46
|
+
* @param {Uint8Array} bytes
|
|
47
|
+
* @returns {Db}
|
|
48
|
+
*/
|
|
49
|
+
static fromBytes(bytes) {
|
|
50
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
51
|
+
const len0 = WASM_VECTOR_LEN;
|
|
52
|
+
const ret = wasm.db_fromBytes(ptr0, len0);
|
|
53
|
+
if (ret[2]) {
|
|
54
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
55
|
+
}
|
|
56
|
+
return Db.__wrap(ret[0]);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a new, empty in-memory database.
|
|
60
|
+
*/
|
|
61
|
+
constructor() {
|
|
62
|
+
const ret = wasm.db_new();
|
|
63
|
+
this.__wbg_ptr = ret;
|
|
64
|
+
DbFinalization.register(this, this.__wbg_ptr, this);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run one SQL statement. Returns a **JSON string** (call `JSON.parse` in JS):
|
|
69
|
+
* `{"columns":[...],"rows":[[...]]}` for `SELECT`, `{"mutated":n}` for
|
|
70
|
+
* `INSERT`/`UPDATE`/`DELETE`, or `{"done":true}` otherwise. Throws the error
|
|
71
|
+
* message (a string) on failure.
|
|
72
|
+
* @param {string} sql
|
|
73
|
+
* @returns {string}
|
|
74
|
+
*/
|
|
75
|
+
query(sql) {
|
|
76
|
+
let deferred3_0;
|
|
77
|
+
let deferred3_1;
|
|
78
|
+
try {
|
|
79
|
+
const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
80
|
+
const len0 = WASM_VECTOR_LEN;
|
|
81
|
+
const ret = wasm.db_query(this.__wbg_ptr, ptr0, len0);
|
|
82
|
+
var ptr2 = ret[0];
|
|
83
|
+
var len2 = ret[1];
|
|
84
|
+
if (ret[3]) {
|
|
85
|
+
ptr2 = 0; len2 = 0;
|
|
86
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
87
|
+
}
|
|
88
|
+
deferred3_0 = ptr2;
|
|
89
|
+
deferred3_1 = len2;
|
|
90
|
+
return getStringFromWasm0(ptr2, len2);
|
|
91
|
+
} finally {
|
|
92
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (Symbol.dispose) Db.prototype[Symbol.dispose] = Db.prototype.free;
|
|
97
|
+
export function __wbg___wbindgen_throw_ea4887a5f8f9a9db(arg0, arg1) {
|
|
98
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
99
|
+
}
|
|
100
|
+
export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
|
|
101
|
+
let deferred0_0;
|
|
102
|
+
let deferred0_1;
|
|
103
|
+
try {
|
|
104
|
+
deferred0_0 = arg0;
|
|
105
|
+
deferred0_1 = arg1;
|
|
106
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
107
|
+
} finally {
|
|
108
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function __wbg_new_227d7c05414eb861() {
|
|
112
|
+
const ret = new Error();
|
|
113
|
+
return ret;
|
|
114
|
+
}
|
|
115
|
+
export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
|
|
116
|
+
const ret = arg1.stack;
|
|
117
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
118
|
+
const len1 = WASM_VECTOR_LEN;
|
|
119
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
120
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
121
|
+
}
|
|
122
|
+
export function __wbindgen_cast_0000000000000001(arg0, arg1) {
|
|
123
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
124
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
125
|
+
return ret;
|
|
126
|
+
}
|
|
127
|
+
export function __wbindgen_init_externref_table() {
|
|
128
|
+
const table = wasm.__wbindgen_externrefs;
|
|
129
|
+
const offset = table.grow(4);
|
|
130
|
+
table.set(0, undefined);
|
|
131
|
+
table.set(offset + 0, undefined);
|
|
132
|
+
table.set(offset + 1, null);
|
|
133
|
+
table.set(offset + 2, true);
|
|
134
|
+
table.set(offset + 3, false);
|
|
135
|
+
}
|
|
136
|
+
const DbFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
137
|
+
? { register: () => {}, unregister: () => {} }
|
|
138
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_db_free(ptr, 1));
|
|
139
|
+
|
|
140
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
141
|
+
ptr = ptr >>> 0;
|
|
142
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let cachedDataViewMemory0 = null;
|
|
146
|
+
function getDataViewMemory0() {
|
|
147
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
148
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
149
|
+
}
|
|
150
|
+
return cachedDataViewMemory0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function getStringFromWasm0(ptr, len) {
|
|
154
|
+
return decodeText(ptr >>> 0, len);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let cachedUint8ArrayMemory0 = null;
|
|
158
|
+
function getUint8ArrayMemory0() {
|
|
159
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
160
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
161
|
+
}
|
|
162
|
+
return cachedUint8ArrayMemory0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
166
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
167
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
168
|
+
WASM_VECTOR_LEN = arg.length;
|
|
169
|
+
return ptr;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
173
|
+
if (realloc === undefined) {
|
|
174
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
175
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
176
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
177
|
+
WASM_VECTOR_LEN = buf.length;
|
|
178
|
+
return ptr;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let len = arg.length;
|
|
182
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
183
|
+
|
|
184
|
+
const mem = getUint8ArrayMemory0();
|
|
185
|
+
|
|
186
|
+
let offset = 0;
|
|
187
|
+
|
|
188
|
+
for (; offset < len; offset++) {
|
|
189
|
+
const code = arg.charCodeAt(offset);
|
|
190
|
+
if (code > 0x7F) break;
|
|
191
|
+
mem[ptr + offset] = code;
|
|
192
|
+
}
|
|
193
|
+
if (offset !== len) {
|
|
194
|
+
if (offset !== 0) {
|
|
195
|
+
arg = arg.slice(offset);
|
|
196
|
+
}
|
|
197
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
198
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
199
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
200
|
+
|
|
201
|
+
offset += ret.written;
|
|
202
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
WASM_VECTOR_LEN = offset;
|
|
206
|
+
return ptr;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function takeFromExternrefTable0(idx) {
|
|
210
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
211
|
+
wasm.__externref_table_dealloc(idx);
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
216
|
+
cachedTextDecoder.decode();
|
|
217
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
218
|
+
let numBytesDecoded = 0;
|
|
219
|
+
function decodeText(ptr, len) {
|
|
220
|
+
numBytesDecoded += len;
|
|
221
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
222
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
223
|
+
cachedTextDecoder.decode();
|
|
224
|
+
numBytesDecoded = len;
|
|
225
|
+
}
|
|
226
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const cachedTextEncoder = new TextEncoder();
|
|
230
|
+
|
|
231
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
232
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
233
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
234
|
+
view.set(buf);
|
|
235
|
+
return {
|
|
236
|
+
read: arg.length,
|
|
237
|
+
written: buf.length
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let WASM_VECTOR_LEN = 0;
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
let wasm;
|
|
246
|
+
export function __wbg_set_wasm(val) {
|
|
247
|
+
wasm = val;
|
|
248
|
+
}
|
package/picovolt_bg.wasm
ADDED
|
Binary file
|