@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.
@@ -1893,6 +1893,50 @@ var ChainBuilder = class _ChainBuilder {
1893
1893
  const rows = await this.ctx.executor.execute(limited, this.ctx.model);
1894
1894
  return rows[0] ?? null;
1895
1895
  }
1896
+ /**
1897
+ * Build and return every SQL query that `findMany` would execute,
1898
+ * without running them. Walks the full plan tree including nested
1899
+ * includes, returning the root query and one child per include level.
1900
+ *
1901
+ * Include children use placeholder `IN (?)` filters since the real
1902
+ * parent key values are only known at execution time.
1903
+ *
1904
+ * Accepts a `QueryEngine` to produce adapter-specific SQL. Pass the
1905
+ * adapter's engine for the dialect you want to inspect:
1906
+ *
1907
+ * const explained = chain.toSQL(biref.adapters.get('postgres').engine);
1908
+ */
1909
+ toSQL(engine) {
1910
+ return _ChainBuilder.explainPlan(this.plan, engine, this.ctx.model);
1911
+ }
1912
+ static explainPlan(plan, engine, model) {
1913
+ const built = engine.build(plan.spec, model);
1914
+ const childExplained = [];
1915
+ for (const include of plan.includes) {
1916
+ const childPlan = _ChainBuilder.buildExplainChildPlan(include);
1917
+ childExplained.push(_ChainBuilder.explainPlan(childPlan, engine, model));
1918
+ }
1919
+ return {
1920
+ entity: `${plan.spec.namespace}.${plan.spec.entity}`,
1921
+ sql: built.command,
1922
+ params: built.params,
1923
+ includes: childExplained
1924
+ };
1925
+ }
1926
+ static buildExplainChildPlan(include) {
1927
+ const filters = [...include.plan.spec.filters ?? []];
1928
+ for (const childKey of include.childKeys) {
1929
+ filters.push({
1930
+ field: childKey,
1931
+ operator: "in",
1932
+ value: ["?"]
1933
+ });
1934
+ }
1935
+ return {
1936
+ ...include.plan,
1937
+ spec: { ...include.plan.spec, filters }
1938
+ };
1939
+ }
1896
1940
  /**
1897
1941
  * Escape hatch for advanced callers (tests, tooling): exposes the
1898
1942
  * accumulated plan without executing it. The typed builder's public