git-sqlite-vfs 0.0.9 → 0.0.11

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.
Files changed (3) hide show
  1. package/README.md +27 -29
  2. package/index.js +8 -0
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,42 +1,40 @@
1
1
  # git-sqlite-vfs
2
2
 
3
- A Git-Versioned SQLite Database powered by a custom native Virtual File System (VFS).
3
+ A Git-versioned SQLite database utilizing a custom Virtual File System (VFS).
4
4
 
5
- By combining the robustness of native SQLite, Drizzle ORM, and libSQL with the distributed tracking power of Git, `git-sqlite-vfs` enables you to version, diff, and merge your application's database exactly like your source code. It works out-of-the-box in both **Node.js** and **Deno**.
5
+ By integrating SQLite, Drizzle ORM, and libSQL with Git, `git-sqlite-vfs` enables versioning, diffing, and merging of SQLite databases. It is compatible with Node.js and Deno.
6
6
 
7
7
  ## Architecture
8
8
 
9
- Traditional SQLite databases are stored as a single flat file, making them difficult to version control because a 1-byte insertion can trigger a cascading byte shift across the entire file, rendering delta-compression useless.
9
+ Standard SQLite databases are stored as a single file. This limits version control compatibility, as minor insertions cause cascading byte shifts, negating delta-compression and creating unresolvable binary merge conflicts.
10
10
 
11
- This package dynamically loads a specialized SQLite C Extension that overrides the default VFS. It shards your database into 4KB deterministic binary pages inside a targeted directory (e.g. `.my-db`).
11
+ This package provides a loadable SQLite C extension that overrides the default VFS behavior. It shards the database into deterministic 4KB binary pages within a specified directory (e.g. `.my-db`).
12
12
 
13
- When you merge branches, our custom `git-merge-sqlitevfs` driver is natively hooked into Git's conflict resolution pipeline to properly reconcile binary B-Tree page conflicts, ensuring absolute data integrity!
13
+ During a Git merge, a custom `git-merge-sqlitevfs` driver integrates with Git's conflict resolution pipeline to reconcile B-Tree page conflicts.
14
14
 
15
15
  ## Installation
16
16
 
17
- Install the VFS package alongside your libSQL and Drizzle tools:
18
-
19
17
  ```bash
20
18
  npm install git-sqlite-vfs @libsql/client drizzle-orm
21
19
  ```
22
20
 
23
- ## Git Setup
21
+ ## Git Configuration
24
22
 
25
- To enable Git versioning and binary merging, you must configure your repository to use the custom merge driver. We provide a convenient CLI to wire everything up:
23
+ The repository must be configured to use the custom merge driver. This configuration occurs automatically when `bootstrapGitVFS()` is called:
26
24
 
27
- ```bash
28
- npx git-sqlite-setup --vfs-dir .my-db
29
- ```
25
+ 1. Registers `git-merge-sqlitevfs` as a custom Git merge driver in the local `.git/config`.
26
+ 2. Updates `.gitattributes` in the repository root to route files matching the configured directory (e.g., `.my-db/*`) through the custom merge driver.
27
+ 3. Updates `.gitignore` to ignore SQLite transient files (`*-journal`, `*-wal`, `*-shm`).
28
+
29
+ ### Source Code Compatibility
30
30
 
31
- This will:
32
- 1. Register `git-merge-sqlitevfs` as a custom Git merge driver in your local `.git/config`.
33
- 2. Create or append to a `.gitattributes` file in your repo root to route all files in `.my-db/*` through the custom merge driver.
31
+ The custom SQLite merge driver scopes to the designated database directory via `.gitattributes`. Other repository files continue using Git's default text-based merge algorithms.
34
32
 
35
- ## Usage (Isomorphic)
33
+ ## Usage
36
34
 
37
- The VFS works transparently in both Node.js and Deno. By using the `bootstrapGitVFS()` method before you initialize `@libsql/client`, the native memory spaces are perfectly synchronized.
35
+ The VFS operates in Node.js and Deno environments. Calling `bootstrapGitVFS()` prior to initializing `@libsql/client` loads the extension process-wide.
38
36
 
39
- ### Using `@libsql/client` with Drizzle ORM
37
+ ### Example with `@libsql/client` and Drizzle ORM
40
38
 
41
39
  ```typescript
42
40
  import { createClient } from '@libsql/client'; // In Deno: 'npm:@libsql/client/node'
@@ -44,47 +42,47 @@ import { drizzle } from 'drizzle-orm/libsql';
44
42
  import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core';
45
43
  import { bootstrapGitVFS } from 'git-sqlite-vfs';
46
44
 
47
- // 1. Load the native extension process-wide and set the VFS directory
45
+ // Load the native extension process-wide and set the VFS directory
48
46
  await bootstrapGitVFS({ dir: '.my-db' });
49
47
 
50
- // 2. Initialize your database connection using a standard file: URL
48
+ // Initialize the database connection using a file URL
51
49
  const client = createClient({
52
50
  url: 'file:.my-db/local.db'
53
51
  });
54
52
 
55
- // 3. Wrap with Drizzle ORM
53
+ // Wrap with Drizzle ORM
56
54
  const db = drizzle(client);
57
55
 
58
- // 4. Define your schema
56
+ // Define the schema
59
57
  const users = sqliteTable('users', {
60
58
  id: integer('id').primaryKey(),
61
59
  name: text('name')
62
60
  });
63
61
 
64
- // 5. Query natively! All I/O is safely intercepted by the Git VFS.
62
+ // Execute queries
65
63
  await db.insert(users).values({ id: 1, name: 'Alice' });
66
64
  const allUsers = await db.select().from(users);
67
65
 
68
66
  console.log(allUsers);
69
67
  ```
70
68
 
71
- ## Preventing Git Bloat
69
+ ## Database Compaction
72
70
 
73
- Because SQLite usually zeroes out deleted data pages rather than shrinking the file, you might accumulate "zombie" `.bin` pages in your repository over time. To ensure the Git VFS automatically garbage-collects these abandoned chunks, you must configure SQLite to run `FULL` auto-vacuuming and use `DELETE` journaling.
71
+ SQLite often zeroes out deleted data pages rather than shrinking the file size, causing unneeded `.bin` pages to remain. To allow the Git VFS to remove these unused shards, configure SQLite to use `FULL` auto-vacuuming and `DELETE` journaling.
74
72
 
75
- Run these PRAGMAs once when initializing your database connection:
73
+ Execute these PRAGMA statements during connection initialization:
76
74
 
77
75
  ```sql
78
76
  PRAGMA auto_vacuum = FULL;
79
77
  PRAGMA journal_mode = DELETE;
80
78
  ```
81
79
 
82
- Or run `VACUUM;` periodically. When SQLite explicitly shrinks the database file, the underlying VFS `xTruncate` routine will physically `unlink()` the out-of-bounds `.bin` shards, keeping your Git tracking history perfectly compressed!
80
+ Alternatively, executing `VACUUM;` periodically reduces the database file size, and the VFS `xTruncate` implementation will remove out-of-bounds `.bin` shards.
83
81
 
84
82
  ## Compatibility
85
83
 
86
- - **Node.js**: v22.5+ (using the new `node:sqlite` API internally) or fallback to `better-sqlite3`.
87
- - **Deno**: Supported automatically (loads the extension dynamically via `jsr:@db/sqlite`).
84
+ - **Node.js**: v22.5+ (using the internal `node:sqlite` API) or fallback to `better-sqlite3`.
85
+ - **Deno**: Supported natively (loads the extension dynamically via `jsr:@db/sqlite`).
88
86
 
89
87
  ## License
90
88
 
package/index.js CHANGED
@@ -53,6 +53,14 @@ export async function bootstrapGitVFS(options = {}) {
53
53
  const db = new Database(':memory:');
54
54
  db.loadExtension(currentExtPath);
55
55
  db.close();
56
+
57
+ try {
58
+ const repoDir = typeof Deno !== 'undefined' ? Deno.cwd() : process.cwd();
59
+ const vfsDir = options.dir || '.db';
60
+ await configureGitIntegration({ repoDir, vfsDir });
61
+ } catch (e) {
62
+ // Ignore errors if git is not available or not in a git repository
63
+ }
56
64
  }
57
65
 
58
66
  export async function configureGitIntegration({ repoDir, vfsDir }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-sqlite-vfs",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "A Git-Versioned SQLite Database via a Custom Virtual File System (VFS)",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -24,9 +24,9 @@
24
24
  "scripts": {
25
25
  "build": "cd c && make",
26
26
  "postinstall": "node install.js",
27
- "pretest": "npm run build && rm -rf .db test.db .test-db .compaction-db .git && git init --initial-branch=master",
27
+ "pretest": "npm run build && rm -rf .db test.db .test-db .compaction-db .git .gitattributes .gitignore && git init --initial-branch=master",
28
28
  "test": "node --test test/*.node.test.js",
29
- "test:deno": "npm run build && rm -rf .db test.db .test-db .git && git init --initial-branch=master && deno test -A test/*.deno.test.ts"
29
+ "test:deno": "npm run build && rm -rf .db test.db .test-db .git .gitattributes .gitignore && git init --initial-branch=master && deno test -A test/*.deno.test.ts"
30
30
  },
31
31
  "dependencies": {
32
32
  "@libsql/client": "^0.14.0",