@mastra/clickhouse 1.25.0 → 1.25.1-alpha.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.js CHANGED
@@ -942,12 +942,23 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
942
942
  query_params: { messageIds }
943
943
  });
944
944
  if (threadIds.length > 0) {
945
- const now = (/* @__PURE__ */ new Date()).toISOString().replace("Z", "");
946
- await this.client.command({
947
- query: `ALTER TABLE ${TABLE_THREADS} UPDATE updatedAt = {now:DateTime64(3)} WHERE id IN {threadIds:Array(String)}`,
948
- query_params: {
949
- now,
950
- threadIds
945
+ const now = Date.now();
946
+ const existingThreads = await this.getLatestThreads(threadIds);
947
+ if (existingThreads.size > 0) await this.client.insert({
948
+ table: TABLE_THREADS,
949
+ format: "JSONEachRow",
950
+ values: Array.from(existingThreads.values()).map((existingThread) => ({
951
+ id: existingThread.id,
952
+ resourceId: existingThread.resourceId,
953
+ title: existingThread.title,
954
+ metadata: serializeMetadata(existingThread.metadata),
955
+ createdAt: existingThread.createdAt,
956
+ updatedAt: new Date(Math.max(now, new Date(existingThread.updatedAt).getTime() + 1)).toISOString().replace("Z", "")
957
+ })),
958
+ clickhouse_settings: {
959
+ date_time_input_format: "best_effort",
960
+ use_client_time_zone: 1,
961
+ output_format_json_quote_64bit_integers: 0
951
962
  }
952
963
  });
953
964
  }