@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.
@@ -5217,11 +5217,14 @@ class BaseDrizzleAdapter extends import_core10.DatabaseAdapter {
5217
5217
  async addParticipant(entityId, roomId) {
5218
5218
  return this.withDatabase(async () => {
5219
5219
  try {
5220
- await this.db.insert(participantTable).values({
5221
- entityId,
5222
- roomId,
5223
- agentId: this.agentId
5224
- }).onConflictDoNothing();
5220
+ const existing = await this.db.select({ id: participantTable.id }).from(participantTable).where(import_drizzle_orm28.and(import_drizzle_orm28.eq(participantTable.entityId, entityId), import_drizzle_orm28.eq(participantTable.roomId, roomId), import_drizzle_orm28.eq(participantTable.agentId, this.agentId))).limit(1);
5221
+ if (existing.length === 0) {
5222
+ await this.db.insert(participantTable).values({
5223
+ entityId,
5224
+ roomId,
5225
+ agentId: this.agentId
5226
+ });
5227
+ }
5225
5228
  return true;
5226
5229
  } catch (error) {
5227
5230
  import_core10.logger.error({
@@ -5238,12 +5241,16 @@ class BaseDrizzleAdapter extends import_core10.DatabaseAdapter {
5238
5241
  async addParticipantsRoom(entityIds, roomId) {
5239
5242
  return this.withDatabase(async () => {
5240
5243
  try {
5241
- const values = entityIds.map((id) => ({
5242
- entityId: id,
5243
- roomId,
5244
- agentId: this.agentId
5245
- }));
5246
- await this.db.insert(participantTable).values(values).onConflictDoNothing().execute();
5244
+ for (const id of entityIds) {
5245
+ const existing = await this.db.select({ id: participantTable.id }).from(participantTable).where(import_drizzle_orm28.and(import_drizzle_orm28.eq(participantTable.entityId, id), import_drizzle_orm28.eq(participantTable.roomId, roomId), import_drizzle_orm28.eq(participantTable.agentId, this.agentId))).limit(1);
5246
+ if (existing.length === 0) {
5247
+ await this.db.insert(participantTable).values({
5248
+ entityId: id,
5249
+ roomId,
5250
+ agentId: this.agentId
5251
+ });
5252
+ }
5253
+ }
5247
5254
  return true;
5248
5255
  } catch (error) {
5249
5256
  import_core10.logger.error({
@@ -5393,19 +5400,27 @@ class BaseDrizzleAdapter extends import_core10.DatabaseAdapter {
5393
5400
  }
5394
5401
  async getRelationships(params) {
5395
5402
  return this.withDatabase(async () => {
5396
- const { entityId, tags } = params;
5397
- let query;
5403
+ const { entityIds: rawEntityIds, entityId, tags, limit, offset } = params;
5404
+ const entityIds = (rawEntityIds && rawEntityIds.length > 0 ? rawEntityIds : entityId ? [entityId] : []).filter((id) => typeof id === "string" && id.trim().length > 0);
5405
+ if (entityIds.length === 0) {
5406
+ return [];
5407
+ }
5408
+ const entityFilter = import_drizzle_orm28.sql.join(entityIds.map((id) => import_drizzle_orm28.sql`(${relationshipTable.sourceEntityId} = ${id} OR ${relationshipTable.targetEntityId} = ${id})`), import_drizzle_orm28.sql` OR `);
5409
+ let query = import_drizzle_orm28.sql`
5410
+ SELECT * FROM ${relationshipTable}
5411
+ WHERE (${entityFilter})
5412
+ `;
5398
5413
  if (tags && tags.length > 0) {
5399
5414
  query = import_drizzle_orm28.sql`
5400
- SELECT * FROM ${relationshipTable}
5401
- WHERE (${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId})
5415
+ ${query}
5402
5416
  AND ${relationshipTable.tags} && CAST(ARRAY[${import_drizzle_orm28.sql.join(tags, import_drizzle_orm28.sql`, `)}] AS text[])
5403
5417
  `;
5404
- } else {
5405
- query = import_drizzle_orm28.sql`
5406
- SELECT * FROM ${relationshipTable}
5407
- WHERE ${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId}
5408
- `;
5418
+ }
5419
+ if (typeof limit === "number") {
5420
+ query = import_drizzle_orm28.sql`${query} LIMIT ${limit}`;
5421
+ }
5422
+ if (typeof offset === "number" && offset > 0) {
5423
+ query = import_drizzle_orm28.sql`${query} OFFSET ${offset}`;
5409
5424
  }
5410
5425
  const result = await this.db.execute(query);
5411
5426
  return result.rows.map((relationship) => ({
@@ -7130,5 +7145,5 @@ var plugin = {
7130
7145
  };
7131
7146
  var typescript_default = plugin;
7132
7147
 
7133
- //# debugId=30BB64705897BABA64756E2164756E21
7148
+ //# debugId=B2FA58A515BC4FB464756E2164756E21
7134
7149
  //# sourceMappingURL=index.node.cjs.map