@mastra/clickhouse 0.13.0-alpha.2 → 0.13.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
@@ -1611,7 +1611,7 @@ var StoreOperationsClickhouse = class extends StoreOperations {
1611
1611
  const hasUpdatedAt = TABLE_SCHEMAS[tableName]?.updatedAt;
1612
1612
  const selectClause = `SELECT *, toDateTime64(createdAt, 3) as createdAt${hasUpdatedAt ? ", toDateTime64(updatedAt, 3) as updatedAt" : ""}`;
1613
1613
  const result = await this.client.query({
1614
- query: `${selectClause} FROM ${tableName} ${engine.startsWith("ReplacingMergeTree") ? "FINAL" : ""} WHERE ${conditions}`,
1614
+ query: `${selectClause} FROM ${tableName} ${engine.startsWith("ReplacingMergeTree") ? "FINAL" : ""} WHERE ${conditions} ORDER BY createdAt DESC LIMIT 1`,
1615
1615
  query_params: values,
1616
1616
  clickhouse_settings: {
1617
1617
  // Allows to insert serialized JS Dates (such as '2023-12-06T10:54:48.000Z')
@@ -1810,12 +1810,30 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1810
1810
  }
1811
1811
  async getScoresByScorerId({
1812
1812
  scorerId,
1813
+ entityId,
1814
+ entityType,
1815
+ source,
1813
1816
  pagination
1814
1817
  }) {
1818
+ let whereClause = `scorerId = {var_scorerId:String}`;
1819
+ if (entityId) {
1820
+ whereClause += ` AND entityId = {var_entityId:String}`;
1821
+ }
1822
+ if (entityType) {
1823
+ whereClause += ` AND entityType = {var_entityType:String}`;
1824
+ }
1825
+ if (source) {
1826
+ whereClause += ` AND source = {var_source:String}`;
1827
+ }
1815
1828
  try {
1816
1829
  const countResult = await this.client.query({
1817
- query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE scorerId = {var_scorerId:String}`,
1818
- query_params: { var_scorerId: scorerId },
1830
+ query: `SELECT COUNT(*) as count FROM ${TABLE_SCORERS} WHERE ${whereClause}`,
1831
+ query_params: {
1832
+ var_scorerId: scorerId,
1833
+ var_entityId: entityId,
1834
+ var_entityType: entityType,
1835
+ var_source: source
1836
+ },
1819
1837
  format: "JSONEachRow"
1820
1838
  });
1821
1839
  const countRows = await countResult.json();
@@ -1837,11 +1855,14 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1837
1855
  }
1838
1856
  const offset = pagination.page * pagination.perPage;
1839
1857
  const result = await this.client.query({
1840
- query: `SELECT * FROM ${TABLE_SCORERS} WHERE scorerId = {var_scorerId:String} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
1858
+ query: `SELECT * FROM ${TABLE_SCORERS} WHERE ${whereClause} ORDER BY createdAt DESC LIMIT {var_limit:Int64} OFFSET {var_offset:Int64}`,
1841
1859
  query_params: {
1842
1860
  var_scorerId: scorerId,
1843
1861
  var_limit: pagination.perPage,
1844
- var_offset: offset
1862
+ var_offset: offset,
1863
+ var_entityId: entityId,
1864
+ var_entityType: entityType,
1865
+ var_source: source
1845
1866
  },
1846
1867
  format: "JSONEachRow",
1847
1868
  clickhouse_settings: {
@@ -2393,6 +2414,7 @@ var WorkflowsStorageClickhouse = class extends WorkflowsStorage {
2393
2414
  resourceId
2394
2415
  FROM ${TABLE_WORKFLOW_SNAPSHOT} ${TABLE_ENGINES[TABLE_WORKFLOW_SNAPSHOT].startsWith("ReplacingMergeTree") ? "FINAL" : ""}
2395
2416
  ${whereClause}
2417
+ ORDER BY createdAt DESC LIMIT 1
2396
2418
  `,
2397
2419
  query_params: values,
2398
2420
  format: "JSONEachRow"
@@ -2639,9 +2661,12 @@ var ClickhouseStore = class extends MastraStorage {
2639
2661
  }
2640
2662
  async getScoresByScorerId({
2641
2663
  scorerId,
2642
- pagination
2664
+ pagination,
2665
+ entityId,
2666
+ entityType,
2667
+ source
2643
2668
  }) {
2644
- return this.stores.scores.getScoresByScorerId({ scorerId, pagination });
2669
+ return this.stores.scores.getScoresByScorerId({ scorerId, pagination, entityId, entityType, source });
2645
2670
  }
2646
2671
  async close() {
2647
2672
  await this.db.close();