-
Notifications
You must be signed in to change notification settings - Fork 7
BREAKING CHANGE: update: migrate to better-sqlite3 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
BREAKING CHANGE: update: migrate to better-sqlite3 #20
Conversation
Greptile OverviewGreptile SummaryThis PR migrates the database layer from Key changes:
Issues:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant API as API Endpoint
participant Entity as Entity Class
participant DB as better-sqlite3
Note over DB: Migration from sqlite3<br/>to better-sqlite3
Client->>API: HTTP Request (e.g., POST /comment)
rect rgb(240, 240, 255)
Note right of API: Before: async callbacks
Note right of API: After: synchronous calls
end
API->>Entity: insert(...columns)
Entity->>Entity: generateInsertSql()
Entity->>Entity: execSql(sql, values)
rect rgb(255, 240, 240)
Note over Entity,DB: Key API Change
Entity->>DB: db.prepare(sql)
DB-->>Entity: PreparedStatement
Entity->>DB: stmt.reader ? stmt.all() : stmt.run()
alt SELECT query (reader=true)
DB-->>Entity: rows[]
else INSERT/UPDATE/DELETE (reader=false)
DB-->>Entity: {changes, lastInsertRowid}
Note right of Entity: ⚠️ Returns [] instead<br/>of run() result
Entity-->>API: []
end
end
alt comment.js pattern
Note over API: Insert returns [], so fetch separately
API->>Entity: get([columns], [where])
Entity->>DB: db.prepare(sql).all()
DB-->>Entity: rows[]
Entity-->>API: rows[]
API-->>Client: {comment: row}
else plugin.js pattern
API->>Entity: increment(column, value, where)
Entity->>DB: db.prepare(UPDATE...).run()
DB-->>Entity: {changes}
Entity-->>API: []
API-->>Client: response
end
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 2 comments
This comment was marked as outdated.
This comment was marked as outdated.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@greptileai Review it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, 4 comments
Additional Comments (1)
In the paid-download flow, |
|
@greptileai Review it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 2 comments
| if (!download) { | ||
| await Download.insert(...columns); | ||
| await Plugin.increment(Plugin.DOWNLOADS, 1, [Plugin.ID, id]); | ||
| await Plugin.increment(Plugin.DOWNLOADS, String(1), [Plugin.ID, id]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increment already accepts a number per entity.js:231, no need to stringify
| await Plugin.increment(Plugin.DOWNLOADS, String(1), [Plugin.ID, id]); | |
| await Plugin.increment(Plugin.DOWNLOADS, 1, [Plugin.ID, id]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greptileai Stringifying of them is important here, else downloads in the Database end up as 1.0 or 2.0 instead of 1 or 2.
| // (if needed, in future) `result` could be set as { rows: [], changes: ..., lastInsertRowid: ... } | ||
| // for now, we'll just set it as an empty array | ||
| stmt.run(...values); | ||
| result = []; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write operations (INSERT/UPDATE/DELETE) now return empty array instead of the actual result info (changes, lastInsertRowid). If callers ever need the insert ID or affected row count, they won't have access to it. This could break code that relies on these values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be handled in future if needed, Currently it returns empty array for compatibility
Why
sqlite3 has received no updates in the past 2-3 years and has blockers on package updating, like tar/node-tar, which has vulnerabilities.
Better-sqlite3 is benchmarked to be faster, better, and more updated in comparison to sqlite3.
I've tested as much as I could; breaking changes could occur because of how the better-sqlite3 API is without callbacks.
To Do
The update schema script needs changes.