Repository navigation
fix(memory): cap the limit with LIMIT -1 when offset is supplied without a limit #1498
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@voltagent/cloudflare-d1": patch | ||
| "@voltagent/libsql": patch | ||
| --- | ||
|
|
||
| Fix offset-only pagination in the D1 and libSQL memory adapters: queryConversations and queryWorkflowRuns with an offset but no limit now emit `LIMIT -1` before `OFFSET` instead of a statement SQLite rejects with `near "OFFSET": syntax error`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -985,6 +985,9 @@ export class D1MemoryAdapter implements StorageAdapter { | |
| if (options.limit) { | ||
| sql += " LIMIT ?"; | ||
| args.push(options.limit); | ||
| } else if (options.offset) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| // SQLite requires LIMIT before OFFSET; -1 caps nothing. | ||
| sql += " LIMIT -1"; | ||
| } | ||
|
|
||
| if (options.offset) { | ||
|
|
@@ -1389,6 +1392,9 @@ export class D1MemoryAdapter implements StorageAdapter { | |
| if (query.limit !== undefined) { | ||
| sql += " LIMIT ?"; | ||
| args.push(query.limit); | ||
| } else if (query.offset !== undefined) { | ||
| // SQLite requires LIMIT before OFFSET; -1 caps nothing. | ||
| sql += " LIMIT -1"; | ||
| } | ||
|
|
||
| if (query.offset !== undefined) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -915,6 +915,9 @@ export class LibSQLMemoryCore implements StorageAdapter { | |
| if (options.limit) { | ||
| sql += " LIMIT ?"; | ||
| args.push(options.limit); | ||
| } else if (options.offset) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This branch treats Prompt for AI agents |
||
| // SQLite requires LIMIT before OFFSET; -1 caps nothing. | ||
| sql += " LIMIT -1"; | ||
| } | ||
|
|
||
| if (options.offset) { | ||
|
|
@@ -1228,6 +1231,9 @@ export class LibSQLMemoryCore implements StorageAdapter { | |
| if (query.limit !== undefined) { | ||
| sql += " LIMIT ?"; | ||
| args.push(query.limit); | ||
| } else if (query.offset !== undefined) { | ||
| // SQLite requires LIMIT before OFFSET; -1 caps nothing. | ||
| sql += " LIMIT -1"; | ||
| } | ||
|
|
||
| if (query.offset !== undefined) { | ||
|
|
||
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.
Bind an explicit zero limit.
With
{ limit: 0, offset: 2 }, the truthiness check falls through to this branch. The query returns rows after the offset instead of returning none. The same issue exists inpackages/libsql/src/memory-core.tsat Line 918.In both adapters, check whether
options.limitis defined and bind zero asLIMIT ?. The linked issue requires explicit limits, including zero, to remain bound.