Comparing version 0.0.5 to 0.1.0
154
lib/main.js
(function() { | ||
'use strict'; | ||
var CND, E, PATH, SQL, badge, debug, echo, guy, help, info, isa, rpr, type_of, types, urge, validate, validate_list_of, warn, whisper; | ||
var CND, E, PATH, SQL, badge, debug, echo, guy, help, info, isa, new_bsqlt3_connection, rpr, type_of, types, urge, validate, validate_list_of, warn, whisper; | ||
@@ -39,4 +39,6 @@ //########################################################################################################### | ||
new_bsqlt3_connection = require('better-sqlite3'); | ||
//----------------------------------------------------------------------------------------------------------- | ||
types.declare('dba_urlsafe_word', { | ||
types.declare('dbay_urlsafe_word', { | ||
tests: { | ||
@@ -67,4 +69,4 @@ "@isa.nonempty_text x": function(x) { | ||
}, | ||
"@isa_optional.dba_urlsafe_word x.dbnick": function(x) { | ||
return this.isa_optional.dba_urlsafe_word(x.dbnick); | ||
"@isa_optional.dbay_urlsafe_word x.dbnick": function(x) { | ||
return this.isa_optional.dbay_urlsafe_word(x.dbnick); | ||
} | ||
@@ -74,7 +76,72 @@ } | ||
//=========================================================================================================== | ||
this.Dbay_rnd = (function() { | ||
class Dbay_rnd { | ||
_initialize_prng() { | ||
var clasz, delta, ref, ref1, ref2, ref3, seed; | ||
clasz = this.constructor; | ||
if (clasz._rnd_int_cfg != null) { | ||
seed = (ref = (ref1 = clasz._rnd_int_cfg) != null ? ref1.seed : void 0) != null ? ref : 12.34; | ||
delta = (ref2 = (ref3 = clasz._rnd_int_cfg) != null ? ref3.delta : void 0) != null ? ref2 : 1; | ||
guy.props.def(this, '_rnd_int', { | ||
enumerable: false, | ||
value: CND.get_rnd_int(seed, delta) | ||
}); | ||
} else { | ||
guy.props.def(this, '_rnd_int', { | ||
enumerable: false, | ||
value: CND.random_integer.bind(CND) | ||
}); | ||
} | ||
return null; | ||
} | ||
//--------------------------------------------------------------------------------------------------------- | ||
_get_connection_url(dbnick = null) { | ||
/* TAINT rename `dbnick` to `dbnick` */ | ||
/* Given an optional `dbnick`, return an object with the `dbnick` and the `url` for a new SQLite | ||
connection. The url will look like `'file:your_name_here?mode=memory&cache=shared` so multiple | ||
connections to the same RAM DB can be opened. When `dbnick` is not given, a random dbnick like | ||
`_icql_6200294332` will be chosen (prefix `_icql_`, suffix ten decimal digits). For testing, setting | ||
class property `@_rnd_int_cfg` can be used to obtain repeatable series of random names. */ | ||
var n10, url; | ||
n10 = this._rnd_int(1_000_000_000, 9_999_999_999); | ||
if (dbnick == null) { | ||
dbnick = `_${n10}`; | ||
} | ||
url = `file:${dbnick}?mode=memory&cache=shared`; | ||
return {url, dbnick}; | ||
} | ||
}; | ||
//========================================================================================================= | ||
// RANDOM NUMBER GENERATION | ||
// seedable for testing purposes | ||
//--------------------------------------------------------------------------------------------------------- | ||
/* To obtain a class with a seedable PRNG that emits repeatable sequences, define class property | ||
`@_rnd_int_cfg: { seed, delta, }` where both seed and delta can be arbitrary finite numbers. **NOTE** | ||
very small `delta` values (like 1e-10) may cause adjacent numbers to be close together or even repeat. To | ||
use default values for both parameters, set `@_rnd_int_cfg: true`.*/ | ||
Dbay_rnd._rnd_int_cfg = null; | ||
return Dbay_rnd; | ||
}).call(this); | ||
//=========================================================================================================== | ||
this.Dbay = (function() { | ||
class Dbay { | ||
class Dbay extends this.Dbay_rnd { | ||
//--------------------------------------------------------------------------------------------------------- | ||
static cast_sqlt_cfg(self) { | ||
var R; | ||
R = guy.obj.pluck_with_fallback(self.cfg, null, 'readonly', 'timeout'); | ||
R.fileMustExist = !self.cfg.create; | ||
delete self.cfg.create; | ||
return R; | ||
} | ||
//--------------------------------------------------------------------------------------------------------- | ||
static cast_constructor_cfg(self) { | ||
var base, base1, dbnick, k, ref, ref1, url, v; | ||
var base, base1, dbnick, ref, url; | ||
// debug '^344476^', self | ||
@@ -100,10 +167,6 @@ // debug '^344476^', self.cfg | ||
} | ||
ref1 = self.cfg; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
if (v == null) { | ||
self.cfg[k] = null; | ||
} | ||
} | ||
return self.cfg; | ||
// self.cfg = guy.obj.nullify_undefined self.cfg | ||
self.sqlt_cfg = guy.lft.freeze(guy.obj.omit_nullish(this.cast_sqlt_cfg(self))); | ||
self.cfg = guy.lft.freeze(guy.obj.omit_nullish(self.cfg)); | ||
return null; | ||
} | ||
@@ -114,3 +177,3 @@ | ||
// debug '^133^', self.cfg, Object.isFrozen self.cfg | ||
self.cfg = this.cast_constructor_cfg(self); | ||
this.cast_constructor_cfg(self); | ||
self.types.validate.constructor_cfg(self.cfg); | ||
@@ -122,8 +185,21 @@ // guy.props.def self, 'dba', { enumerable: false, value: self.cfg.dba, } | ||
//--------------------------------------------------------------------------------------------------------- | ||
_new_bsqlt3_connection() { | ||
var path_or_url; | ||
path_or_url = this.cfg.ram ? this.cfg.url : this.cfg.path; | ||
return new_bsqlt3_connection(path_or_url, this.sqlt_cfg); | ||
} | ||
//--------------------------------------------------------------------------------------------------------- | ||
constructor(cfg) { | ||
//--------------------------------------------------------------------------------------------------------- | ||
this._get_connection_url = this._get_connection_url.bind(this); | ||
// super() | ||
super(); | ||
this._initialize_prng(); | ||
guy.cfg.configure_with_types(this, cfg, types); | ||
guy.props.def(this, 'sqlt1', { | ||
enumerable: false, | ||
value: this._new_bsqlt3_connection() | ||
}); | ||
guy.props.def(this, 'sqlt2', { | ||
enumerable: false, | ||
value: this._new_bsqlt3_connection() | ||
}); | ||
// @_compile_sql() | ||
@@ -135,30 +211,2 @@ // @_create_sql_functions() | ||
_initialize_prng() { | ||
var clasz, delta, ref, ref1, seed; | ||
clasz = this.constructor; | ||
if (clasz._rnd_int_cfg != null) { | ||
seed = (ref = clasz._rnd_int_cfg.seed) != null ? ref : 12.34; | ||
delta = (ref1 = clasz._rnd_int_cfg.delta) != null ? ref1 : 1; | ||
this._rnd_int = CND.get_rnd_int(seed, delta); | ||
} else { | ||
this._rnd_int = CND.random_integer.bind(CND); | ||
} | ||
return null; | ||
} | ||
_get_connection_url(dbnick = null) { | ||
var url; | ||
/* TAINT rename `dbnick` to `dbnick` */ | ||
/* Given an optional `dbnick`, return an object with the `dbnick` and the `url` for a new SQLite | ||
connection. The url will look like `'file:your_name_here?mode=memory&cache=shared` so multiple | ||
connections to the same RAM DB can be opened. When `dbnick` is not given, a random dbnick like | ||
`_icql_6200294332` will be chosen (prefix `_icql_`, suffix ten decimal digits). For testing, setting | ||
class property `@_rnd_int_cfg` can be used to obtain repeatable series of random names. */ | ||
if (dbnick == null) { | ||
dbnick = `_icql_${this._rnd_int(1_000_000_000, 9_999_999_999)}`; | ||
} | ||
url = `file:${dbnick}?mode=memory&cache=shared`; | ||
return {url, dbnick}; | ||
} | ||
}; | ||
@@ -170,8 +218,8 @@ | ||
constructor_cfg: { | ||
_temp_prefix: '_dba_temp_', | ||
// _temp_prefix: '_dba_temp_' | ||
readonly: false, | ||
create: true, | ||
overwrite: false, | ||
timeout: 5000, | ||
//................................................................................................... | ||
overwrite: false, | ||
ram: null, | ||
@@ -184,12 +232,2 @@ path: null, | ||
//========================================================================================================= | ||
// RANDOM NUMBER GENERATION | ||
// seedable for testing purposes | ||
//--------------------------------------------------------------------------------------------------------- | ||
/* To obtain a class with a seedable PRNG that emits repeatable sequences, define class property | ||
`@_rnd_int_cfg: { seed, delta, }` where both seed and delta can be arbitrary finite numbers. **NOTE** | ||
very small `delta` values (like 1e-10) may cause adjacent numbers to be close together or even repeat. To | ||
use default values for both parameters, set `@_rnd_int_cfg: true`.*/ | ||
Dbay._rnd_int_cfg = null; | ||
return Dbay; | ||
@@ -196,0 +234,0 @@ |
{ | ||
"name": "dbay", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "In-Process, In-Memory & File-Based Relational Data Processing with SQLite, BetterSQLite3", | ||
@@ -28,7 +28,6 @@ "main": "lib/main.js", | ||
"dependencies": { | ||
"better-sqlite3": "^7.4.3", | ||
"cnd": "9.2.2", | ||
"guy": "^2.0.0", | ||
"guy": "^2.2.0", | ||
"intertype": "7.6.7" | ||
} | ||
} |
@@ -10,2 +10,6 @@ # DBay | ||
- [Introduction](#introduction) | ||
- [Documentation](#documentation) | ||
- [Note on Package Structure](#note-on-package-structure) | ||
- [`better-sqlite3` an 'Unsaved' Dependency](#better-sqlite3-an-unsaved-dependency) | ||
- [Use npm, Not pnpm](#use-npm-not-pnpm) | ||
- [To Do](#to-do) | ||
@@ -32,6 +36,30 @@ | ||
## Documentation | ||
* [`Dbay` object construction](./README-construction.md) | ||
## Note on Package Structure | ||
### `better-sqlite3` an 'Unsaved' Dependency | ||
Since DBay depends on [`better-sqlite3`](https://github.com/JoshuaWise/better-sqlite3) with a | ||
[custom-configured build of the SQLite C | ||
engine](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/compilation.md), it is (for whatever | ||
reason) important that **`better-sqlite3` must not be listed under `package.json#dependencies`**; otherwise, | ||
compilation will not work properly. The [build script](./build-sqlite3) will run `npm install | ||
better-sqlite3@'^7.4.3'` but with an added `--no-save` flag. | ||
## Use npm, Not pnpm | ||
Also, at the time of this writing (2021-09), while the project compiles fine using npm v7.21.1 (on NodeJS | ||
v16.9.1 on Linux Mint), but it fails using pnpm v6.14.6 with `Unknown options: 'build-from-source', | ||
'sqlite3'`. Yarn has not been tried. | ||
**Note**—*These considerations only concern those who wish to fork/clone DBay to work on the code. Those who | ||
just want to use DBay as a dependency of their project can both either run `npm install dbay` or `pnpm add | ||
dbay`, both package managers work fine.* | ||
## To Do | ||
* **[–]** port foundational code from hengist &c | ||
* **[–]** at construction time, allow `dbnick` when `path` is given and `ram` is `false` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11851124
3
53
783
64
0
- Removedbetter-sqlite3@^7.4.3
- Removedbase64-js@1.5.1(transitive)
- Removedbetter-sqlite3@7.6.2(transitive)
- Removedbl@4.1.0(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedchownr@1.1.4(transitive)
- Removeddecompress-response@6.0.0(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedexpand-template@2.0.3(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedgithub-from-package@0.0.0(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedmimic-response@3.1.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp-classic@0.5.3(transitive)
- Removednapi-build-utils@2.0.0(transitive)
- Removednode-abi@3.74.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedprebuild-install@7.1.3(transitive)
- Removedpump@3.0.2(transitive)
- Removedrc@1.2.8(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@7.7.1(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@4.0.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedtar-fs@2.1.2(transitive)
- Removedtar-stream@2.2.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedguy@^2.2.0