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
helper utilities on top of better-sqlite3-helper
npm install better-sqlite3-schema
Typescript
Module System
Node Version
NPM Version
69.5
Supply Chain
97.1
Quality
75.1
Maintenance
100
Vulnerability
99.3
License
TypeScript (99.41%)
Shell (0.59%)
Total Downloads
10,584
Last Day
2
Last Week
27
Last Month
150
Last Year
2,511
BSD-2-Clause License
5 Stars
117 Commits
1 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Feb 19, 2025
Minified
Minified + Gzipped
Latest Version
3.1.8
Package Id
better-sqlite3-schema@3.1.8
Unpacked Size
62.76 kB
Size
15.29 kB
File Count
29
NPM Version
10.9.2
Node Version
22.13.1
Published on
Feb 19, 2025
Cumulative downloads
Total Downloads
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 'better-sqlite3-schema' 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{ 2 "timestamp": 1600713130016, 3 "type": "request", 4 "userAgent": "Mozilla/5.0 (Linux; Android 10; LIO-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36", 5 "referer": "https://www.example.net/sw.js", 6 "protocol": "https", 7 "host": "www.example.net", 8 "method": "GET", 9 "url": "/build/p-7794655c.js" 10}
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
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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 2025-06-30
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 MoreLast Day
0%
2
Compared to previous day
Last Week
125%
27
Compared to previous week
Last Month
-14.8%
150
Compared to previous month
Last Year
-0.6%
2,511
Compared to previous year