MCPcopy
hub / github.com/knex/knex / toSQL

Function toSQL

src/raw.js:72–115  ·  view source on GitHub ↗
(method, tz)

Source from the content-addressed store, hash-verified

70
71 // Returns the raw sql for the query.
72 toSQL(method, tz) {
73 let obj;
74 const formatter = this.client.formatter(this);
75
76 if (Array.isArray(this.bindings)) {
77 obj = replaceRawArrBindings(this, formatter);
78 } else if (this.bindings && isPlainObject(this.bindings)) {
79 obj = replaceKeyBindings(this, formatter);
80 } else {
81 obj = {
82 method: 'raw',
83 sql: this.sql,
84 bindings: isUndefined(this.bindings) ? [] : [this.bindings],
85 };
86 }
87
88 if (this._wrappedBefore) {
89 obj.sql = this._wrappedBefore + obj.sql;
90 }
91 if (this._wrappedAfter) {
92 obj.sql = obj.sql + this._wrappedAfter;
93 }
94
95 obj.options = reduce(this._options, assign, {});
96
97 if (this._timeout) {
98 obj.timeout = this._timeout;
99 if (this._cancelOnTimeout) {
100 obj.cancelOnTimeout = this._cancelOnTimeout;
101 }
102 }
103
104 obj.bindings = obj.bindings || [];
105 if (helpers.containsUndefined(obj.bindings)) {
106 debugBindings(obj.bindings);
107 throw new Error(
108 `Undefined binding(s) detected when compiling RAW query: ` + obj.sql
109 );
110 }
111
112 obj.__knexQueryUid = uuid.v4();
113
114 return obj;
115 },
116});
117
118function replaceRawArrBindings(raw, formatter) {

Callers

nothing calls this directly

Calls 2

replaceRawArrBindingsFunction · 0.85
replaceKeyBindingsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…