@elizaos/plugin-sql 2.0.0-alpha.18 → 2.0.0-alpha.19

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.
@@ -5177,11 +5177,14 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
5177
5177
  async addParticipant(entityId, roomId) {
5178
5178
  return this.withDatabase(async () => {
5179
5179
  try {
5180
- await this.db.insert(participantTable).values({
5181
- entityId,
5182
- roomId,
5183
- agentId: this.agentId
5184
- }).onConflictDoNothing();
5180
+ const existing = await this.db.select({ id: participantTable.id }).from(participantTable).where(and(eq2(participantTable.entityId, entityId), eq2(participantTable.roomId, roomId), eq2(participantTable.agentId, this.agentId))).limit(1);
5181
+ if (existing.length === 0) {
5182
+ await this.db.insert(participantTable).values({
5183
+ entityId,
5184
+ roomId,
5185
+ agentId: this.agentId
5186
+ });
5187
+ }
5185
5188
  return true;
5186
5189
  } catch (error) {
5187
5190
  logger9.error({
@@ -5198,12 +5201,16 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
5198
5201
  async addParticipantsRoom(entityIds, roomId) {
5199
5202
  return this.withDatabase(async () => {
5200
5203
  try {
5201
- const values = entityIds.map((id) => ({
5202
- entityId: id,
5203
- roomId,
5204
- agentId: this.agentId
5205
- }));
5206
- await this.db.insert(participantTable).values(values).onConflictDoNothing().execute();
5204
+ for (const id of entityIds) {
5205
+ const existing = await this.db.select({ id: participantTable.id }).from(participantTable).where(and(eq2(participantTable.entityId, id), eq2(participantTable.roomId, roomId), eq2(participantTable.agentId, this.agentId))).limit(1);
5206
+ if (existing.length === 0) {
5207
+ await this.db.insert(participantTable).values({
5208
+ entityId: id,
5209
+ roomId,
5210
+ agentId: this.agentId
5211
+ });
5212
+ }
5213
+ }
5207
5214
  return true;
5208
5215
  } catch (error) {
5209
5216
  logger9.error({
@@ -5353,19 +5360,27 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
5353
5360
  }
5354
5361
  async getRelationships(params) {
5355
5362
  return this.withDatabase(async () => {
5356
- const { entityId, tags } = params;
5357
- let query;
5363
+ const { entityIds: rawEntityIds, entityId, tags, limit, offset } = params;
5364
+ const entityIds = (rawEntityIds && rawEntityIds.length > 0 ? rawEntityIds : entityId ? [entityId] : []).filter((id) => typeof id === "string" && id.trim().length > 0);
5365
+ if (entityIds.length === 0) {
5366
+ return [];
5367
+ }
5368
+ const entityFilter = sql27.join(entityIds.map((id) => sql27`(${relationshipTable.sourceEntityId} = ${id} OR ${relationshipTable.targetEntityId} = ${id})`), sql27` OR `);
5369
+ let query = sql27`
5370
+ SELECT * FROM ${relationshipTable}
5371
+ WHERE (${entityFilter})
5372
+ `;
5358
5373
  if (tags && tags.length > 0) {
5359
5374
  query = sql27`
5360
- SELECT * FROM ${relationshipTable}
5361
- WHERE (${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId})
5375
+ ${query}
5362
5376
  AND ${relationshipTable.tags} && CAST(ARRAY[${sql27.join(tags, sql27`, `)}] AS text[])
5363
5377
  `;
5364
- } else {
5365
- query = sql27`
5366
- SELECT * FROM ${relationshipTable}
5367
- WHERE ${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId}
5368
- `;
5378
+ }
5379
+ if (typeof limit === "number") {
5380
+ query = sql27`${query} LIMIT ${limit}`;
5381
+ }
5382
+ if (typeof offset === "number" && offset > 0) {
5383
+ query = sql27`${query} OFFSET ${offset}`;
5369
5384
  }
5370
5385
  const result = await this.db.execute(query);
5371
5386
  return result.rows.map((relationship) => ({
@@ -7103,5 +7118,5 @@ export {
7103
7118
  DatabaseMigrationService
7104
7119
  };
7105
7120
 
7106
- //# debugId=11DF3BC6739C08E664756E2164756E21
7121
+ //# debugId=606A9AD08C7E6C2364756E2164756E21
7107
7122
  //# sourceMappingURL=index.node.js.map