From 877e5fbb1950bc628eb3981f0652475894e4cf42 Mon Sep 17 00:00:00 2001 From: moon Date: Wed, 20 Mar 2024 19:30:03 -0700 Subject: [PATCH] Handle unique and order for memories --- package.json | 2 +- src/lib/adapters/sqlite.ts | 9 ++++++--- src/lib/adapters/sqljs.ts | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9be40b5..079e9a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bgent", - "version": "0.1.4", + "version": "0.1.5", "private": false, "description": "bgent. because agent was taken.", "type": "module", diff --git a/src/lib/adapters/sqlite.ts b/src/lib/adapters/sqlite.ts index 05d1780..f0577cb 100644 --- a/src/lib/adapters/sqlite.ts +++ b/src/lib/adapters/sqlite.ts @@ -275,9 +275,12 @@ AND room_id = ?`; const queryParams = [params.tableName, params.room_id]; - // if (params.unique) { - // sql += " AND `unique` = 1"; - // } + if (params.unique) { + sql += " AND `unique` = 1"; + } + + // get the most recent memories + sql += " ORDER BY created_at DESC"; if (params.count) { sql += " LIMIT ?"; diff --git a/src/lib/adapters/sqljs.ts b/src/lib/adapters/sqljs.ts index c6c4d16..2d5903f 100644 --- a/src/lib/adapters/sqljs.ts +++ b/src/lib/adapters/sqljs.ts @@ -300,6 +300,12 @@ export class SqlJsDatabaseAdapter extends DatabaseAdapter { } let sql = `SELECT * FROM memories WHERE type = ? AND room_id = ?`; + if (params.unique) { + sql += " AND `unique` = 1"; + } + + sql += " ORDER BY created_at DESC"; + if (params.count) { sql += " LIMIT ?"; }