@biref/scanner 0.1.0 → 0.2.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.cjs CHANGED
@@ -935,10 +935,10 @@ var MySQLQueryEngine = class {
935
935
  sql += ` ORDER BY ${orderPieces.join(", ")}`;
936
936
  }
937
937
  if (spec.limit !== void 0) {
938
- sql += ` LIMIT ${params.add(spec.limit)}`;
938
+ sql += ` LIMIT ${Number(spec.limit)}`;
939
939
  }
940
940
  if (spec.offset !== void 0) {
941
- sql += ` OFFSET ${params.add(spec.offset)}`;
941
+ sql += ` OFFSET ${Number(spec.offset)}`;
942
942
  }
943
943
  return {
944
944
  command: sql,
@@ -2851,6 +2851,50 @@ var ChainBuilder = class _ChainBuilder {
2851
2851
  const rows = await this.ctx.executor.execute(limited, this.ctx.model);
2852
2852
  return rows[0] ?? null;
2853
2853
  }
2854
+ /**
2855
+ * Build and return every SQL query that `findMany` would execute,
2856
+ * without running them. Walks the full plan tree including nested
2857
+ * includes, returning the root query and one child per include level.
2858
+ *
2859
+ * Include children use placeholder `IN (?)` filters since the real
2860
+ * parent key values are only known at execution time.
2861
+ *
2862
+ * Accepts a `QueryEngine` to produce adapter-specific SQL. Pass the
2863
+ * adapter's engine for the dialect you want to inspect:
2864
+ *
2865
+ * const explained = chain.toSQL(biref.adapters.get('postgres').engine);
2866
+ */
2867
+ toSQL(engine) {
2868
+ return _ChainBuilder.explainPlan(this.plan, engine, this.ctx.model);
2869
+ }
2870
+ static explainPlan(plan, engine, model) {
2871
+ const built = engine.build(plan.spec, model);
2872
+ const childExplained = [];
2873
+ for (const include of plan.includes) {
2874
+ const childPlan = _ChainBuilder.buildExplainChildPlan(include);
2875
+ childExplained.push(_ChainBuilder.explainPlan(childPlan, engine, model));
2876
+ }
2877
+ return {
2878
+ entity: `${plan.spec.namespace}.${plan.spec.entity}`,
2879
+ sql: built.command,
2880
+ params: built.params,
2881
+ includes: childExplained
2882
+ };
2883
+ }
2884
+ static buildExplainChildPlan(include) {
2885
+ const filters = [...include.plan.spec.filters ?? []];
2886
+ for (const childKey of include.childKeys) {
2887
+ filters.push({
2888
+ field: childKey,
2889
+ operator: "in",
2890
+ value: ["?"]
2891
+ });
2892
+ }
2893
+ return {
2894
+ ...include.plan,
2895
+ spec: { ...include.plan.spec, filters }
2896
+ };
2897
+ }
2854
2898
  /**
2855
2899
  * Escape hatch for advanced callers (tests, tooling): exposes the
2856
2900
  * accumulated plan without executing it. The typed builder's public