jsql-neo 5.4.2 → 5.5.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 +202 -202
- package/README.md +8097 -7971
- package/bin/jsql +320 -320
- package/bin/jsql-server +90 -90
- package/bin/jsql-server-control.js +177 -177
- package/index.d.ts +385 -357
- package/index.js +124 -118
- package/lib/ast.js +214 -0
- package/lib/btree.js +413 -413
- package/lib/cache.js +328 -328
- package/lib/client.js +125 -125
- package/lib/database.js +1744 -1744
- package/lib/date-types.js +182 -182
- package/lib/errors.js +89 -89
- package/lib/jsql_format.js +497 -497
- package/lib/migrate.js +254 -254
- package/lib/mod.js +292 -292
- package/lib/mongo_server.js +607 -607
- package/lib/multiserver.js +140 -140
- package/lib/mysql_compat.js +413 -413
- package/lib/mysql_server.js +1237 -1237
- package/lib/native_client.js +732 -732
- package/lib/nedb_compat.js +506 -506
- package/lib/pg_server.js +864 -864
- package/lib/plugin.js +34 -34
- package/lib/query.js +815 -815
- package/lib/redis_server.js +571 -571
- package/lib/sql.js +3460 -2925
- package/lib/sqlite_compat.js +323 -323
- package/lib/sqlite_worker.js +264 -264
- package/lib/table.js +1304 -1304
- package/lib/tui.js +502 -502
- package/lib/wasm.js +1 -1
- package/lib/wasm_client.js +718 -718
- package/lib/web_ui.js +257 -257
- package/native/jsql-neo-native.node +0 -0
- package/nativesrc/jsql-neo-core/Cargo.lock +455 -455
- package/nativesrc/jsql-neo-core/Cargo.toml +24 -24
- package/nativesrc/jsql-neo-core/src/engine/hybrid.rs +455 -455
- package/nativesrc/jsql-neo-core/src/engine/memory.rs +168 -168
- package/nativesrc/jsql-neo-core/src/engine/mod.rs +62 -62
- package/nativesrc/jsql-neo-core/src/engine/table.rs +700 -700
- package/nativesrc/jsql-neo-core/src/lib.rs +2 -2
- package/nativesrc/jsql-neo-core/src/storage/mod.rs +2 -2
- package/nativesrc/jsql-neo-core/src/storage/persistent.rs +1 -1
- package/nativesrc/jsql-neo-core/src/storage/wal.rs +85 -85
- package/nativesrc/jsql-neo-core/src/types.rs +93 -93
- package/nativesrc/jsql-neo-native/Cargo.lock +606 -606
- package/nativesrc/jsql-neo-native/Cargo.toml +16 -16
- package/nativesrc/jsql-neo-native/build.rs +3 -3
- package/nativesrc/jsql-neo-native/package.json +7 -7
- package/nativesrc/jsql-neo-native/src/lib.rs +269 -269
- package/nativesrc/jsql-neo-wasm/Cargo.lock +465 -465
- package/nativesrc/jsql-neo-wasm/Cargo.toml +15 -15
- package/nativesrc/jsql-neo-wasm/src/lib.rs +447 -447
- package/package.json +87 -86
- package/postinstall.js +158 -158
- package/test/btree.test.js +128 -128
- package/test/coverage.js +187 -187
- package/test/join.test.js +110 -110
- package/test/native.test.js +158 -158
- package/test/regress-5.1.0.js +271 -271
- package/test/smoke.js +58 -58
- package/test/sql-parser.test.js +273 -0
- package/test/wasm.test.js +110 -110
- package/wasm/browser.d.ts +89 -89
- package/wasm/browser.mjs +569 -569
- package/wasm/browser_bg.mjs +597 -597
- package/wasm/jsql_neo_wasm.d.ts +38 -38
- package/wasm/jsql_neo_wasm.js +520 -520
- package/wasm/jsql_neo_wasm_bg.wasm.d.ts +26 -26
- package/wasm/package.json +11 -11
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
pub mod engine;
|
|
2
|
-
pub mod storage;
|
|
1
|
+
pub mod engine;
|
|
2
|
+
pub mod storage;
|
|
3
3
|
pub mod types;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
pub mod persistent;
|
|
2
|
-
pub mod wal;
|
|
1
|
+
pub mod persistent;
|
|
2
|
+
pub mod wal;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Persistent storage engine - WIP, not used by native addon
|
|
1
|
+
// Persistent storage engine - WIP, not used by native addon
|
|
2
2
|
// The native addon uses MemoryEngine only
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
use serde::{Deserialize, Serialize};
|
|
2
|
-
use std::io::{Read, Write};
|
|
3
|
-
|
|
4
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
5
|
-
pub enum WalOp {
|
|
6
|
-
CreateTable,
|
|
7
|
-
DropTable,
|
|
8
|
-
Insert,
|
|
9
|
-
Update,
|
|
10
|
-
Remove,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
14
|
-
pub struct WalEntry {
|
|
15
|
-
pub tx_id: u64,
|
|
16
|
-
pub op: WalOp,
|
|
17
|
-
pub data: Vec<u8>,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
pub struct WalWriter {
|
|
21
|
-
path: String,
|
|
22
|
-
file: Option<std::fs::File>,
|
|
23
|
-
next_tx: u64,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
impl WalWriter {
|
|
27
|
-
pub fn open(path: &str) -> std::io::Result<Self> {
|
|
28
|
-
let file = std::fs::OpenOptions::new()
|
|
29
|
-
.create(true)
|
|
30
|
-
.append(true)
|
|
31
|
-
.open(path)?;
|
|
32
|
-
Ok(Self { path: path.to_string(), file: Some(file), next_tx: 1 })
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
#[allow(dead_code)]
|
|
36
|
-
pub fn append(&mut self, op: WalOp, data: Vec<u8>) -> std::io::Result<u64> {
|
|
37
|
-
let tx_id = self.next_tx;
|
|
38
|
-
self.next_tx += 1;
|
|
39
|
-
let entry = WalEntry { tx_id, op, data };
|
|
40
|
-
let buf = bincode::serialize(&entry).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
|
41
|
-
if let Some(ref mut file) = self.file {
|
|
42
|
-
let len = buf.len() as u64;
|
|
43
|
-
file.write_all(&len.to_le_bytes())?;
|
|
44
|
-
file.write_all(&buf)?;
|
|
45
|
-
file.flush()?;
|
|
46
|
-
}
|
|
47
|
-
Ok(tx_id)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
pub fn flush(&mut self) -> std::io::Result<()> {
|
|
51
|
-
if let Some(ref mut file) = self.file {
|
|
52
|
-
file.flush()?;
|
|
53
|
-
}
|
|
54
|
-
Ok(())
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
pub struct WalReader {
|
|
59
|
-
path: String,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
impl WalReader {
|
|
63
|
-
pub fn open(path: &str) -> Self {
|
|
64
|
-
Self { path: path.to_string() }
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
pub fn replay_after(&self, _after_tx: u64) -> std::io::Result<Vec<WalEntry>> {
|
|
68
|
-
let file = match std::fs::File::open(&self.path) {
|
|
69
|
-
Ok(f) => f,
|
|
70
|
-
Err(_) => return Ok(Vec::new()),
|
|
71
|
-
};
|
|
72
|
-
let mut reader = std::io::BufReader::new(file);
|
|
73
|
-
let mut entries = Vec::new();
|
|
74
|
-
loop {
|
|
75
|
-
let mut len_buf = [0u8; 8];
|
|
76
|
-
if reader.read_exact(&mut len_buf).is_err() { break; }
|
|
77
|
-
let len = u64::from_le_bytes(len_buf) as usize;
|
|
78
|
-
let mut buf = vec![0u8; len];
|
|
79
|
-
if reader.read_exact(&mut buf).is_err() { break; }
|
|
80
|
-
if let Ok(entry) = bincode::deserialize::<WalEntry>(&buf) {
|
|
81
|
-
entries.push(entry);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
Ok(entries)
|
|
85
|
-
}
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
|
2
|
+
use std::io::{Read, Write};
|
|
3
|
+
|
|
4
|
+
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
5
|
+
pub enum WalOp {
|
|
6
|
+
CreateTable,
|
|
7
|
+
DropTable,
|
|
8
|
+
Insert,
|
|
9
|
+
Update,
|
|
10
|
+
Remove,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
14
|
+
pub struct WalEntry {
|
|
15
|
+
pub tx_id: u64,
|
|
16
|
+
pub op: WalOp,
|
|
17
|
+
pub data: Vec<u8>,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub struct WalWriter {
|
|
21
|
+
path: String,
|
|
22
|
+
file: Option<std::fs::File>,
|
|
23
|
+
next_tx: u64,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl WalWriter {
|
|
27
|
+
pub fn open(path: &str) -> std::io::Result<Self> {
|
|
28
|
+
let file = std::fs::OpenOptions::new()
|
|
29
|
+
.create(true)
|
|
30
|
+
.append(true)
|
|
31
|
+
.open(path)?;
|
|
32
|
+
Ok(Self { path: path.to_string(), file: Some(file), next_tx: 1 })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[allow(dead_code)]
|
|
36
|
+
pub fn append(&mut self, op: WalOp, data: Vec<u8>) -> std::io::Result<u64> {
|
|
37
|
+
let tx_id = self.next_tx;
|
|
38
|
+
self.next_tx += 1;
|
|
39
|
+
let entry = WalEntry { tx_id, op, data };
|
|
40
|
+
let buf = bincode::serialize(&entry).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
|
41
|
+
if let Some(ref mut file) = self.file {
|
|
42
|
+
let len = buf.len() as u64;
|
|
43
|
+
file.write_all(&len.to_le_bytes())?;
|
|
44
|
+
file.write_all(&buf)?;
|
|
45
|
+
file.flush()?;
|
|
46
|
+
}
|
|
47
|
+
Ok(tx_id)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub fn flush(&mut self) -> std::io::Result<()> {
|
|
51
|
+
if let Some(ref mut file) = self.file {
|
|
52
|
+
file.flush()?;
|
|
53
|
+
}
|
|
54
|
+
Ok(())
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pub struct WalReader {
|
|
59
|
+
path: String,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
impl WalReader {
|
|
63
|
+
pub fn open(path: &str) -> Self {
|
|
64
|
+
Self { path: path.to_string() }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub fn replay_after(&self, _after_tx: u64) -> std::io::Result<Vec<WalEntry>> {
|
|
68
|
+
let file = match std::fs::File::open(&self.path) {
|
|
69
|
+
Ok(f) => f,
|
|
70
|
+
Err(_) => return Ok(Vec::new()),
|
|
71
|
+
};
|
|
72
|
+
let mut reader = std::io::BufReader::new(file);
|
|
73
|
+
let mut entries = Vec::new();
|
|
74
|
+
loop {
|
|
75
|
+
let mut len_buf = [0u8; 8];
|
|
76
|
+
if reader.read_exact(&mut len_buf).is_err() { break; }
|
|
77
|
+
let len = u64::from_le_bytes(len_buf) as usize;
|
|
78
|
+
let mut buf = vec![0u8; len];
|
|
79
|
+
if reader.read_exact(&mut buf).is_err() { break; }
|
|
80
|
+
if let Ok(entry) = bincode::deserialize::<WalEntry>(&buf) {
|
|
81
|
+
entries.push(entry);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
Ok(entries)
|
|
85
|
+
}
|
|
86
86
|
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
use std::collections::HashMap;
|
|
2
|
-
use serde::{Deserialize, Serialize};
|
|
3
|
-
|
|
4
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
5
|
-
pub struct Row {
|
|
6
|
-
pub id: u64,
|
|
7
|
-
pub fields: HashMap<String, serde_json::Value>,
|
|
8
|
-
pub created_at: Option<String>,
|
|
9
|
-
pub updated_at: Option<String>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
13
|
-
pub struct TableDefinition {
|
|
14
|
-
pub name: String,
|
|
15
|
-
#[serde(with = "schema_order_preserving")]
|
|
16
|
-
pub schema: Vec<(String, FieldSchema)>,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/// 保序的对象序列化:JSON 对象 ↔ Vec<(String, FieldSchema)>
|
|
20
|
-
pub mod schema_order_preserving {
|
|
21
|
-
use serde::{Deserialize, Deserializer, Serializer};
|
|
22
|
-
use super::FieldSchema;
|
|
23
|
-
|
|
24
|
-
pub fn serialize<S>(v: &[(String, FieldSchema)], s: S) -> Result<S::Ok, S::Error>
|
|
25
|
-
where
|
|
26
|
-
S: Serializer,
|
|
27
|
-
{
|
|
28
|
-
use serde::ser::SerializeMap;
|
|
29
|
-
let mut m = s.serialize_map(Some(v.len()))?;
|
|
30
|
-
for (k, f) in v {
|
|
31
|
-
m.serialize_entry(k, f)?;
|
|
32
|
-
}
|
|
33
|
-
m.end()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pub fn deserialize<'de, D>(d: D) -> Result<Vec<(String, FieldSchema)>, D::Error>
|
|
37
|
-
where
|
|
38
|
-
D: Deserializer<'de>,
|
|
39
|
-
{
|
|
40
|
-
struct V<'a>(&'a mut Vec<(String, FieldSchema)>);
|
|
41
|
-
impl<'de, 'a> serde::de::Visitor<'de> for V<'a> {
|
|
42
|
-
type Value = ();
|
|
43
|
-
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
44
|
-
f.write_str("a schema object")
|
|
45
|
-
}
|
|
46
|
-
fn visit_map<A>(self, mut a: A) -> Result<(), A::Error>
|
|
47
|
-
where
|
|
48
|
-
A: serde::de::MapAccess<'de>,
|
|
49
|
-
{
|
|
50
|
-
while let Some((k, f)) = a.next_entry::<String, FieldSchema>()? {
|
|
51
|
-
self.0.push((k, f));
|
|
52
|
-
}
|
|
53
|
-
Ok(())
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
let mut out = Vec::new();
|
|
57
|
-
d.deserialize_map(V(&mut out))?;
|
|
58
|
-
Ok(out)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
63
|
-
#[serde(rename_all = "camelCase")]
|
|
64
|
-
pub struct FieldSchema {
|
|
65
|
-
#[serde(rename = "type")]
|
|
66
|
-
pub field_type: FieldType,
|
|
67
|
-
#[serde(default)]
|
|
68
|
-
pub primary_key: bool,
|
|
69
|
-
#[serde(default)]
|
|
70
|
-
pub auto_increment: bool,
|
|
71
|
-
#[serde(default)]
|
|
72
|
-
pub nullable: bool,
|
|
73
|
-
#[serde(default)]
|
|
74
|
-
pub unique: bool,
|
|
75
|
-
#[serde(default)]
|
|
76
|
-
pub length: Option<usize>,
|
|
77
|
-
#[serde(default)]
|
|
78
|
-
pub default: Option<serde_json::Value>,
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
82
|
-
#[serde(rename_all = "lowercase")]
|
|
83
|
-
pub enum FieldType {
|
|
84
|
-
Integer,
|
|
85
|
-
Float,
|
|
86
|
-
String,
|
|
87
|
-
Boolean,
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
impl Default for FieldType {
|
|
91
|
-
fn default() -> Self {
|
|
92
|
-
FieldType::String
|
|
93
|
-
}
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
use serde::{Deserialize, Serialize};
|
|
3
|
+
|
|
4
|
+
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
5
|
+
pub struct Row {
|
|
6
|
+
pub id: u64,
|
|
7
|
+
pub fields: HashMap<String, serde_json::Value>,
|
|
8
|
+
pub created_at: Option<String>,
|
|
9
|
+
pub updated_at: Option<String>,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
13
|
+
pub struct TableDefinition {
|
|
14
|
+
pub name: String,
|
|
15
|
+
#[serde(with = "schema_order_preserving")]
|
|
16
|
+
pub schema: Vec<(String, FieldSchema)>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// 保序的对象序列化:JSON 对象 ↔ Vec<(String, FieldSchema)>
|
|
20
|
+
pub mod schema_order_preserving {
|
|
21
|
+
use serde::{Deserialize, Deserializer, Serializer};
|
|
22
|
+
use super::FieldSchema;
|
|
23
|
+
|
|
24
|
+
pub fn serialize<S>(v: &[(String, FieldSchema)], s: S) -> Result<S::Ok, S::Error>
|
|
25
|
+
where
|
|
26
|
+
S: Serializer,
|
|
27
|
+
{
|
|
28
|
+
use serde::ser::SerializeMap;
|
|
29
|
+
let mut m = s.serialize_map(Some(v.len()))?;
|
|
30
|
+
for (k, f) in v {
|
|
31
|
+
m.serialize_entry(k, f)?;
|
|
32
|
+
}
|
|
33
|
+
m.end()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pub fn deserialize<'de, D>(d: D) -> Result<Vec<(String, FieldSchema)>, D::Error>
|
|
37
|
+
where
|
|
38
|
+
D: Deserializer<'de>,
|
|
39
|
+
{
|
|
40
|
+
struct V<'a>(&'a mut Vec<(String, FieldSchema)>);
|
|
41
|
+
impl<'de, 'a> serde::de::Visitor<'de> for V<'a> {
|
|
42
|
+
type Value = ();
|
|
43
|
+
fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
44
|
+
f.write_str("a schema object")
|
|
45
|
+
}
|
|
46
|
+
fn visit_map<A>(self, mut a: A) -> Result<(), A::Error>
|
|
47
|
+
where
|
|
48
|
+
A: serde::de::MapAccess<'de>,
|
|
49
|
+
{
|
|
50
|
+
while let Some((k, f)) = a.next_entry::<String, FieldSchema>()? {
|
|
51
|
+
self.0.push((k, f));
|
|
52
|
+
}
|
|
53
|
+
Ok(())
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let mut out = Vec::new();
|
|
57
|
+
d.deserialize_map(V(&mut out))?;
|
|
58
|
+
Ok(out)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
63
|
+
#[serde(rename_all = "camelCase")]
|
|
64
|
+
pub struct FieldSchema {
|
|
65
|
+
#[serde(rename = "type")]
|
|
66
|
+
pub field_type: FieldType,
|
|
67
|
+
#[serde(default)]
|
|
68
|
+
pub primary_key: bool,
|
|
69
|
+
#[serde(default)]
|
|
70
|
+
pub auto_increment: bool,
|
|
71
|
+
#[serde(default)]
|
|
72
|
+
pub nullable: bool,
|
|
73
|
+
#[serde(default)]
|
|
74
|
+
pub unique: bool,
|
|
75
|
+
#[serde(default)]
|
|
76
|
+
pub length: Option<usize>,
|
|
77
|
+
#[serde(default)]
|
|
78
|
+
pub default: Option<serde_json::Value>,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
82
|
+
#[serde(rename_all = "lowercase")]
|
|
83
|
+
pub enum FieldType {
|
|
84
|
+
Integer,
|
|
85
|
+
Float,
|
|
86
|
+
String,
|
|
87
|
+
Boolean,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
impl Default for FieldType {
|
|
91
|
+
fn default() -> Self {
|
|
92
|
+
FieldType::String
|
|
93
|
+
}
|
|
94
94
|
}
|