@mastra/clickhouse 1.5.1 → 1.5.2

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
@@ -514,16 +514,11 @@ var ClickhouseDB = class extends MastraBase {
514
514
  }
515
515
  async clearTable({ tableName }) {
516
516
  try {
517
- await this.client.query({
518
- query: `TRUNCATE TABLE ${tableName}`,
519
- clickhouse_settings: {
520
- // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
521
- date_time_input_format: "best_effort",
522
- date_time_output_format: "iso",
523
- use_client_time_zone: 1,
524
- output_format_json_quote_64bit_integers: 0
525
- }
517
+ await this.client.command({ query: `SYSTEM STOP MERGES ${tableName}` });
518
+ await this.client.command({
519
+ query: `TRUNCATE TABLE ${tableName}`
526
520
  });
521
+ await this.client.command({ query: `SYSTEM START MERGES ${tableName}` });
527
522
  } catch (error) {
528
523
  throw new MastraError(
529
524
  {
@@ -785,7 +780,7 @@ var BackgroundTasksStorageClickhouse = class extends BackgroundTasksStorage {
785
780
  const rows = await result.json();
786
781
  return rows.length > 0 ? rowToTask(rows[0]) : null;
787
782
  }
788
- async listTasks(filter) {
783
+ buildFilterClause(filter) {
789
784
  const conditions = [];
790
785
  const params = {};
791
786
  if (filter.status) {
@@ -819,6 +814,10 @@ var BackgroundTasksStorageClickhouse = class extends BackgroundTasksStorage {
819
814
  params.var_to_date = filter.toDate.toISOString();
820
815
  }
821
816
  const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
817
+ return { where, params };
818
+ }
819
+ async listTasks(filter) {
820
+ const { where, params } = this.buildFilterClause(filter);
822
821
  const countResult = await this.client.query({
823
822
  query: `SELECT count() as count FROM ${TABLE_BACKGROUND_TASKS} FINAL ${where}`,
824
823
  query_params: params,
@@ -848,19 +847,18 @@ var BackgroundTasksStorageClickhouse = class extends BackgroundTasksStorage {
848
847
  return { tasks, total };
849
848
  }
850
849
  async deleteTask(taskId) {
851
- await this.client.query({
852
- query: `ALTER TABLE ${TABLE_BACKGROUND_TASKS} DELETE WHERE id = {var_id:String}`,
850
+ await this.client.command({
851
+ query: `DELETE FROM ${TABLE_BACKGROUND_TASKS} WHERE id = {var_id:String}`,
853
852
  query_params: { var_id: taskId }
854
853
  });
855
854
  }
856
855
  async deleteTasks(filter) {
857
- const { tasks } = await this.listTasks(filter);
858
- for (const task of tasks) {
859
- await this.client.query({
860
- query: `ALTER TABLE ${TABLE_BACKGROUND_TASKS} DELETE WHERE id = {var_id:String}`,
861
- query_params: { var_id: task.id }
862
- });
863
- }
856
+ const { where, params } = this.buildFilterClause(filter);
857
+ if (!where) return;
858
+ await this.client.command({
859
+ query: `DELETE FROM ${TABLE_BACKGROUND_TASKS} ${where}`,
860
+ query_params: params
861
+ });
864
862
  }
865
863
  async getRunningCount() {
866
864
  const result = await this.client.query({