@voltagent/libsql 2.0.3 → 2.1.0

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.
package/dist/index.mjs CHANGED
@@ -456,8 +456,12 @@ var LibSQLMemoryCore = class {
456
456
  await this.initialize();
457
457
  const messagesTable = `${this.tablePrefix}_messages`;
458
458
  const { limit, before, after, roles } = options || {};
459
- let sql = `SELECT * FROM ${messagesTable}
460
- WHERE conversation_id = ? AND user_id = ?`;
459
+ let sql = `
460
+ SELECT * FROM (
461
+ SELECT *
462
+ FROM ${messagesTable}
463
+ WHERE conversation_id = ? AND user_id = ?
464
+ `;
461
465
  const args = [conversationId, userId];
462
466
  if (roles && roles.length > 0) {
463
467
  const placeholders = roles.map(() => "?").join(",");
@@ -472,11 +476,12 @@ var LibSQLMemoryCore = class {
472
476
  sql += " AND created_at > ?";
473
477
  args.push(after.toISOString());
474
478
  }
475
- sql += " ORDER BY created_at ASC";
479
+ sql += " ORDER BY created_at DESC";
476
480
  if (limit && limit > 0) {
477
481
  sql += " LIMIT ?";
478
482
  args.push(limit);
479
483
  }
484
+ sql += " ) AS subq ORDER BY created_at ASC";
480
485
  const result = await this.client.execute({ sql, args });
481
486
  return result.rows.map((row) => {
482
487
  let parts;