@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.
|
@@ -5080,11 +5080,14 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
5080
5080
|
async addParticipant(entityId, roomId) {
|
|
5081
5081
|
return this.withDatabase(async () => {
|
|
5082
5082
|
try {
|
|
5083
|
-
await this.db.
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5083
|
+
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);
|
|
5084
|
+
if (existing.length === 0) {
|
|
5085
|
+
await this.db.insert(participantTable).values({
|
|
5086
|
+
entityId,
|
|
5087
|
+
roomId,
|
|
5088
|
+
agentId: this.agentId
|
|
5089
|
+
});
|
|
5090
|
+
}
|
|
5088
5091
|
return true;
|
|
5089
5092
|
} catch (error) {
|
|
5090
5093
|
logger9.error({
|
|
@@ -5101,12 +5104,16 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
5101
5104
|
async addParticipantsRoom(entityIds, roomId) {
|
|
5102
5105
|
return this.withDatabase(async () => {
|
|
5103
5106
|
try {
|
|
5104
|
-
const
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5107
|
+
for (const id of entityIds) {
|
|
5108
|
+
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);
|
|
5109
|
+
if (existing.length === 0) {
|
|
5110
|
+
await this.db.insert(participantTable).values({
|
|
5111
|
+
entityId: id,
|
|
5112
|
+
roomId,
|
|
5113
|
+
agentId: this.agentId
|
|
5114
|
+
});
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5110
5117
|
return true;
|
|
5111
5118
|
} catch (error) {
|
|
5112
5119
|
logger9.error({
|
|
@@ -5256,19 +5263,27 @@ class BaseDrizzleAdapter extends DatabaseAdapter {
|
|
|
5256
5263
|
}
|
|
5257
5264
|
async getRelationships(params) {
|
|
5258
5265
|
return this.withDatabase(async () => {
|
|
5259
|
-
const { entityId, tags } = params;
|
|
5260
|
-
|
|
5266
|
+
const { entityIds: rawEntityIds, entityId, tags, limit, offset } = params;
|
|
5267
|
+
const entityIds = (rawEntityIds && rawEntityIds.length > 0 ? rawEntityIds : entityId ? [entityId] : []).filter((id) => typeof id === "string" && id.trim().length > 0);
|
|
5268
|
+
if (entityIds.length === 0) {
|
|
5269
|
+
return [];
|
|
5270
|
+
}
|
|
5271
|
+
const entityFilter = sql27.join(entityIds.map((id) => sql27`(${relationshipTable.sourceEntityId} = ${id} OR ${relationshipTable.targetEntityId} = ${id})`), sql27` OR `);
|
|
5272
|
+
let query = sql27`
|
|
5273
|
+
SELECT * FROM ${relationshipTable}
|
|
5274
|
+
WHERE (${entityFilter})
|
|
5275
|
+
`;
|
|
5261
5276
|
if (tags && tags.length > 0) {
|
|
5262
5277
|
query = sql27`
|
|
5263
|
-
|
|
5264
|
-
WHERE (${relationshipTable.sourceEntityId} = ${entityId} OR ${relationshipTable.targetEntityId} = ${entityId})
|
|
5278
|
+
${query}
|
|
5265
5279
|
AND ${relationshipTable.tags} && CAST(ARRAY[${sql27.join(tags, sql27`, `)}] AS text[])
|
|
5266
5280
|
`;
|
|
5267
|
-
}
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5281
|
+
}
|
|
5282
|
+
if (typeof limit === "number") {
|
|
5283
|
+
query = sql27`${query} LIMIT ${limit}`;
|
|
5284
|
+
}
|
|
5285
|
+
if (typeof offset === "number" && offset > 0) {
|
|
5286
|
+
query = sql27`${query} OFFSET ${offset}`;
|
|
5272
5287
|
}
|
|
5273
5288
|
const result = await this.db.execute(query);
|
|
5274
5289
|
return result.rows.map((relationship) => ({
|
|
@@ -6720,5 +6735,5 @@ export {
|
|
|
6720
6735
|
DatabaseMigrationService
|
|
6721
6736
|
};
|
|
6722
6737
|
|
|
6723
|
-
//# debugId=
|
|
6738
|
+
//# debugId=3F35670A53EFAB1F64756E2164756E21
|
|
6724
6739
|
//# sourceMappingURL=index.browser.js.map
|