git-sqlite-vfs 0.0.9 → 0.0.10

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 +26 -26
  2. package/index.js +8 -0
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,42 +1,42 @@
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 powered by 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 native SQLite, Drizzle ORM, and libSQL with Git's version control capabilities, `git-sqlite-vfs` allows you to version, diff, and merge your application's database in a manner similar to source code. It is compatible with both **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 flat file. This structure presents challenges for version control, as a minor insertion can result in widespread byte shifts across the file, reducing the effectiveness of delta-compression and making binary merge conflicts difficult to resolve.
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 4KB deterministic 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 provided `git-merge-sqlitevfs` driver integrates with Git's conflict resolution pipeline to reconcile binary B-Tree page conflicts, maintaining data integrity.
14
14
 
15
15
  ## Installation
16
16
 
17
- Install the VFS package alongside your libSQL and Drizzle tools:
17
+ Install the package alongside your libSQL and Drizzle ORM dependencies:
18
18
 
19
19
  ```bash
20
20
  npm install git-sqlite-vfs @libsql/client drizzle-orm
21
21
  ```
22
22
 
23
- ## Git Setup
23
+ ## Git Configuration
24
24
 
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:
25
+ To enable Git versioning and binary merging, the repository must be configured to use the custom merge driver. This is done **automatically** when you call `bootstrapGitVFS()`:
26
26
 
27
- ```bash
28
- npx git-sqlite-setup --vfs-dir .my-db
29
- ```
27
+ 1. It registers `git-merge-sqlitevfs` as a custom Git merge driver in the local `.git/config`.
28
+ 2. It adds or appends to a `.gitattributes` file in the repository root to route all files matching your configured directory (e.g., `.my-db/*`) through the custom merge driver.
29
+ 3. It creates or updates a `.gitignore` to ignore SQLite transient files (`*-journal`, `*-wal`, `*-shm`).
30
+
31
+ ### Safe alongside Source Code
30
32
 
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.
33
+ The custom SQLite merge driver **will not interfere with the merging of standard source code or text files**. By utilizing the `.gitattributes` file, Git explicitly scopes the custom driver strictly to the files within your designated database directory (e.g., `.my-db/* merge=sqlitevfs`). All other files in your repository will continue to use Git's default text-based merge algorithms.
34
34
 
35
- ## Usage (Isomorphic)
35
+ ## Usage
36
36
 
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.
37
+ The VFS works in both Node.js and Deno environments. By calling the `bootstrapGitVFS()` method prior to initializing `@libsql/client`, the extension is loaded process-wide.
38
38
 
39
- ### Using `@libsql/client` with Drizzle ORM
39
+ ### Example with `@libsql/client` and Drizzle ORM
40
40
 
41
41
  ```typescript
42
42
  import { createClient } from '@libsql/client'; // In Deno: 'npm:@libsql/client/node'
@@ -47,7 +47,7 @@ import { bootstrapGitVFS } from 'git-sqlite-vfs';
47
47
  // 1. Load the native extension process-wide and set the VFS directory
48
48
  await bootstrapGitVFS({ dir: '.my-db' });
49
49
 
50
- // 2. Initialize your database connection using a standard file: URL
50
+ // 2. Initialize the database connection using a standard file: URL
51
51
  const client = createClient({
52
52
  url: 'file:.my-db/local.db'
53
53
  });
@@ -55,36 +55,36 @@ const client = createClient({
55
55
  // 3. Wrap with Drizzle ORM
56
56
  const db = drizzle(client);
57
57
 
58
- // 4. Define your schema
58
+ // 4. Define the schema
59
59
  const users = sqliteTable('users', {
60
60
  id: integer('id').primaryKey(),
61
61
  name: text('name')
62
62
  });
63
63
 
64
- // 5. Query natively! All I/O is safely intercepted by the Git VFS.
64
+ // 5. Execute queries. File I/O is intercepted by the Git VFS.
65
65
  await db.insert(users).values({ id: 1, name: 'Alice' });
66
66
  const allUsers = await db.select().from(users);
67
67
 
68
68
  console.log(allUsers);
69
69
  ```
70
70
 
71
- ## Preventing Git Bloat
71
+ ## Preventing Repository Bloat
72
72
 
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.
73
+ Because SQLite often zeroes out deleted data pages rather than shrinking the database file size, "zombie" `.bin` pages may accumulate in the repository over time. To allow the Git VFS to automatically garbage-collect these unused chunks, configure SQLite to use `FULL` auto-vacuuming and `DELETE` journaling.
74
74
 
75
- Run these PRAGMAs once when initializing your database connection:
75
+ Execute these PRAGMA statements when initializing the database connection:
76
76
 
77
77
  ```sql
78
78
  PRAGMA auto_vacuum = FULL;
79
79
  PRAGMA journal_mode = DELETE;
80
80
  ```
81
81
 
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!
82
+ Alternatively, you can run `VACUUM;` periodically. When SQLite explicitly reduces the database file size, the underlying VFS `xTruncate` implementation will remove the out-of-bounds `.bin` shards, keeping the repository history compressed.
83
83
 
84
84
  ## Compatibility
85
85
 
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`).
86
+ - **Node.js**: v22.5+ (using the internal `node:sqlite` API) or fallback to `better-sqlite3`.
87
+ - **Deno**: Supported natively (loads the extension dynamically via `jsr:@db/sqlite`).
88
88
 
89
89
  ## License
90
90
 
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.10",
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",