Gathering detailed insights and metrics for better-sqlite3-schema
Gathering detailed insights and metrics for better-sqlite3-schema
Gathering detailed insights and metrics for better-sqlite3-schema
Gathering detailed insights and metrics for better-sqlite3-schema
npm install better-sqlite3-schema
Typescript
Module System
Node Version
NPM Version
62.3
Supply Chain
97.1
Quality
77.5
Maintenance
100
Vulnerability
99.3
License
TypeScript (99.41%)
Shell (0.59%)
Total Downloads
9,643
Last Day
3
Last Week
10
Last Month
88
Last Year
2,620
5 Stars
115 Commits
1 Forks
2 Watching
1 Branches
1 Contributors
Latest Version
3.1.7
Package Id
better-sqlite3-schema@3.1.7
Unpacked Size
64.15 kB
Size
15.42 kB
File Count
29
NPM Version
10.8.1
Node Version
20.12.2
Publised On
17 Jun 2024
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
-16.7%
10
Compared to previous week
Last month
-50%
88
Compared to previous month
Last year
-9.7%
2,620
Compared to previous year
3
3
Migrate (nested and multi-dimensional) json data to/from sqlite database with better-sqlite3-helper
Sample json data type:
1interface Thread { 2 tid: number 3 subject: string 4 uid: string 5 author: string 6 posts: Post[] 7 tags: string[] 8} 9 10interface Post { 11 pid: number 12 uid: string 13 author: string 14 content: string 15 imgs: string[] 16}
Sample table schema:
1import { TableSchema } from '.' 2 3const threadSchema: TableSchema = { 4 table: 'thread', 5 fields: { 6 tid: 'integer', 7 subject: 'text', 8 uid: 'integer', 9 }, 10 refFields: ['type'], 11} 12 13const threadTagSchema: TableSchema = { 14 table: 'thread_tag', 15 fields: { 16 tid: 'integer', 17 }, 18 refFields: ['tag'], 19} 20 21const postSchema: TableSchema = { 22 table: 'post', 23 fields: { 24 pid: 'integer', 25 tid: 'integer', 26 uid: 'integer', 27 content: 'text', 28 }, 29} 30 31const postImgSchema: TableSchema = { 32 table: 'post_img', 33 fields: { 34 pid: 'integer', 35 }, 36 refFields: ['img'], 37}
The functional approach allows one to compose customizable helper functions at runtime.
Explore the dataset and auto built schema with
makeSchemaScanner()
Compose insert functions with
makeInsertRowFnFromSchema()
makeDeduplicatedInsertRowFnFromSchema()
Compose select functions with
makeSelectRowFnFromSchema()
makeSelectRefFieldArray()
makeGetRefValueFnFromSchema()
Detail example see makePredefinedInsertRowFn()
and makeGeneralInsertRowFn()
in functional-test.ts
The code generation approach allows one to compose customizable helper functions at build-time. Which can archive ~50% speed up compared to the runtime composing.
8GiB of HTTP proxy server log. Each line is a compact json text.
Sample text:
1{"timestamp":1600713130016,"type":"request","userAgent":"Mozilla/5.0 (Linux; Android 10; LIO-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36","referer":"https://www.example.net/sw.js","protocol":"https","host":"www.example.net","method":"GET","url":"/build/p-7794655c.js"}
When stored into sqlite3, the data are normalized into multiple tables to avoid duplication, e.g. only storing the full text of each type of user agent and url once.
File size in varies format:
storage | size | size compared with plain text | Remark |
---|---|---|---|
plain text | 8256M | - | |
sqlite without index | 920M | 11.1% | |
zip of non-indexed sqlite file | 220M | 2.7% | 23.9% of sqlite3 file |
sqlite with indices | 1147M | 13.9% | +24% of sqlite file |
zip of indexed sqlite file | 268M | 3.2% | 23.4% of indexed sqlite3 file |
Time used to import:
Optimization used:
PRAGMA synchronous = OFF
PRAGMA journal_mode = MEMORY
PRAGMA cache_size = ${(200 * 1000 ** 2) / 4}
(default page size is 4K, we largely increase the cache_size to avoid massive tedious disk write)Remark:
Using index increases the file size by 1/4, but hugely speeds up the import process.
To archive the best of both aspects, create indices during import; and remove indices (then VACUUM) for archive file.
It takes 4.9s to build the indices; and 16.3s to vacuum the database after removal of indices.
291119 sample json data crawled from online forum (threads and posts)
Total size: 843M
The objects have consistent shape.
Some data are duplicated, e.g. user name, and some common comments.
Same as the dataset used in binary-object
File size in varies format:
storage | size |
---|---|
json text | 843M |
sqlite3 with index | 669M |
sqlite3 without index | 628M |
zip of sqlite3 without index | 171M |
Remark: The data in sqlite3 are normalized to avoid duplication
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More