
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
jsite-database
Advanced tools
npm install jsite-database
const path = require("path");
const JSiteDatabase = require("jsite-database");
/**
* Initiate Container
*/
let Database1 = new JSiteDatabase();
// ...or with options,
let Database2 = new JSiteDatabase({
format: {
indent: " "
},
mysql: {
host: "localhost",
user: "AzureDiamond",
password: "hunter2",
database: "reddit"
},
sql: {
language: "mysql",
options: {
quoteIdentifiers: true
}
},
audit: "column",
files: {
db: path.join(__dirname, "private", "mysql")
}
});
/**
* Start container
*/
Database1.ready()
.then(() => {
// Database ready
})
.catch(console.log);
| Name | Type (default) | Description |
|---|---|---|
| format | Object ({}) | Arguments for "sql-formatter" module |
| mysql | Object ({}) | Arguments for "mysql" module |
| sql | Object ({ language: "sqlite", options: {} }) | Language & arguments for "json-sql-builder2" module |
| audit | String ("row") | Desired auditing method (see "Options (audit)") |
| files | Object ({}) | Custom file location |
JSiteDatabase has two built-in audit methods ("row" and "column"), "row" will setup full slowly changing dimension (SCD) tables - these take the core structure of SCD 4, with some improvements. "column" will track individual field changes - this is, most of the time, worse than "row". You can also pass "all" to enable both auditing methods.
| Field | Description |
|---|---|
| id__history__last | ID of previous SCD row for this record |
| id__history | ID of current SCD row for this record |
| id__history__next | ID of next SCD row for this record |
| (column)__updated | Whether the (column) updated in this change (1/0) |
| (column)__last | Previous value for the (column) for this record |
| (column) | Current value for the (column) for this record |
| (column)__next | Next value for the (column) for this record |
| Field | Description |
|---|---|
| id__changes__last | ID of previous changes row for this field in this record |
| id__changes | ID of current changes row for this field in this record |
| id__changes__next | ID of next changes row for this field in this record |
| id | Primary key for this record |
| field | Field name being changed in this record |
| value__last | Previous value for this field in this record |
| value | Current value for this field in this record |
| value__next | Next value for this field in this record |
Both auditing tables contain the following SCD columns,
| Field | Description |
|---|---|
| scd__start | Datetime (or timestamp in SQLite) for this record being used (EffecitveFrom) |
| scd__end | Datetime (or timestamp in SQLite) for this record being used (EffectiveTo) |
| scd__duration | Number of seconds this record was active for |
| scd__event | SQL event that caused this record (insert, update, delete) |
By default the file location will be: <current dir>/private/db/ (the location can be changed with the "files" option, see above) inside of here, the module will create the following structure:
└───private
└───db
│ index.db
│
├───sql
│ alter.sql
│ custom.sql
│ tables.sql
│ views.sql
│
├───tables
│ tables1.json
│ tables2.json
│ tables3.js
│ tbl1.sql
│ tbl2.sql
│ tbl3.sql
│ tbl4.sql
│
└───views
view1.json
view1.sql
view2.json
view2.sql
view3.sql
view4.js
view4.sql
By default the tables directory will be empty, you can populate this with your table schema files, these should be in JSON format. You can prefix the file with an underscore (i.e. _tables3.json) if you do not want it to be built.
index.db will only exist if the container has been started using sqlite
By default the tables.sql file will contain all of the SQL required to make your database schema, each table and trigger will use "IF NOT EXISTS", to prevent duplication or accidental removal of tables in the database. You can inspect this file to see exactly what is being executed during the .ready() process.
By default the alter.sql file will not be created on first startup, this file is created when the module notices differences between your database and your schema files. This file will contain the SQL needed to alter your database from what exists to what the schema describes - beware that this is only basic, it cannot handle columns being renamed or datatypes changing (currently, datatypes is an enhancement I'm looking to add). You can inspect this file to see exactly what is being executed during the .ready() process.
Your tables schema files should be in JSON format and follow the json-sql-builder format for the .$createTable() method (see their documentation). An example of this format is the following:
{
"$table": "my_table_name",
"$define": {
"column_name": {
"$column": {
"$type": "VARCHAR",
"$size": 11
}
}
}
}
Each JSON file can contain multiple tables:
[
{
"$table": "my_table_name1",
"$define": {
"column_name": {
"$column": {
"$type": "VARCHAR",
"$size": 11
}
}
}
},
{
"$table": "my_table_name2",
"$define": {
"column_name": {
"$column": {
"$type": "VARCHAR",
"$size": 11
}
}
}
}
]
You can ommit the $table and $define option, if your JSON file has only one table. This will set $define to your JSON and $table to the name of the JSON file (without the .json), as an example:
{
"column_name": {
"$column": {
"$type": "VARCHAR",
"$size": 11
}
}
}
...will be turned into...
{
"$table": "my_table_name3",
"$define": {
"column_name": {
"$column": {
"$type": "VARCHAR",
"$size": 11
}
}
}
}
Under the $define property you can supply a priority (named as $priority), this will sort the table in the produced SQL file/executed queries. This is supplied along with columns so that it can be used in the minimal file format, shown above.
List of things that I'm looking to add to the module, this list is not in priority order.
Detection of datatype changes in alter
alter.sql fileSupport for further database software
Further SCD support
Built-in validation
Implementation of previous version "get", "put", "patch", "delete"
FAQs
Database module for the JSite package
We found that jsite-database demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.