sql-love 1.0.2 → 1.0.4

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.
Files changed (56) hide show
  1. package/README.md +52 -32
  2. package/dist/index.cjs +16 -0
  3. package/dist/index.d.ts +732 -9
  4. package/dist/index.mjs +16 -0
  5. package/package.json +29 -12
  6. package/.github/workflows/node.js.yml +0 -37
  7. package/.prettierrc.json +0 -13
  8. package/CHANGELOG.md +0 -39
  9. package/CONTRIBUTING.md +0 -85
  10. package/assets/sql-love-logo.png +0 -0
  11. package/codecov.yml +0 -7
  12. package/dist/index.js +0 -9
  13. package/dist/src/Parser/Parser.d.ts +0 -157
  14. package/dist/src/Parser/Parser.js +0 -304
  15. package/dist/src/SelectBuilder/SelectBuilder.d.ts +0 -379
  16. package/dist/src/SelectBuilder/SelectBuilder.js +0 -810
  17. package/dist/src/extractGrouped/extractGrouped.d.ts +0 -17
  18. package/dist/src/extractGrouped/extractGrouped.js +0 -31
  19. package/dist/src/extractIndexed/extractIndexed.d.ts +0 -12
  20. package/dist/src/extractIndexed/extractIndexed.js +0 -23
  21. package/dist/src/extractLookup/extractLookup.d.ts +0 -9
  22. package/dist/src/extractLookup/extractLookup.js +0 -21
  23. package/dist/src/getPagination/getPagination.d.ts +0 -16
  24. package/dist/src/getPagination/getPagination.js +0 -40
  25. package/dist/src/runMysql/runMysql.d.ts +0 -58
  26. package/dist/src/runMysql/runMysql.js +0 -61
  27. package/dist/src/runPrisma/runPrisma.d.ts +0 -41
  28. package/dist/src/runPrisma/runPrisma.js +0 -34
  29. package/dist/src/substrCount/substrCount.d.ts +0 -6
  30. package/dist/src/substrCount/substrCount.js +0 -14
  31. package/dist/src/toSafeJson/toSafeJson.d.ts +0 -25
  32. package/dist/src/toSafeJson/toSafeJson.js +0 -45
  33. package/index.ts +0 -19
  34. package/src/Parser/Parser.spec.ts +0 -226
  35. package/src/Parser/Parser.ts +0 -325
  36. package/src/SelectBuilder/SelectBuilder.spec.ts +0 -785
  37. package/src/SelectBuilder/SelectBuilder.ts +0 -914
  38. package/src/extractGrouped/extractGrouped.spec.ts +0 -43
  39. package/src/extractGrouped/extractGrouped.ts +0 -36
  40. package/src/extractIndexed/extractIndexed.spec.ts +0 -40
  41. package/src/extractIndexed/extractIndexed.ts +0 -28
  42. package/src/extractLookup/extractLookup.spec.ts +0 -38
  43. package/src/extractLookup/extractLookup.ts +0 -33
  44. package/src/getPagination/getPagination.spec.ts +0 -75
  45. package/src/getPagination/getPagination.ts +0 -42
  46. package/src/runMysql/runMysql.spec.ts +0 -286
  47. package/src/runMysql/runMysql.ts +0 -106
  48. package/src/runPrisma/runPrisma.spec.ts +0 -99
  49. package/src/runPrisma/runPrisma.ts +0 -75
  50. package/src/substrCount/substrCount.spec.ts +0 -29
  51. package/src/substrCount/substrCount.ts +0 -14
  52. package/src/toSafeJson/toSafeJson.spec.ts +0 -28
  53. package/src/toSafeJson/toSafeJson.ts +0 -56
  54. package/tsconfig.build.json +0 -10
  55. package/tsconfig.json +0 -22
  56. package/vitest.config.ts +0 -11
@@ -1,304 +0,0 @@
1
- /**
2
- * Parse SQL and populate onto a Select query object
3
- */
4
- export default class Parser {
5
- query;
6
- /**
7
- * Create a new instance
8
- * @param query A Select object on which to build parsed conditions
9
- */
10
- constructor(query) {
11
- this.query = query;
12
- }
13
- /**
14
- * Strip single-line and multi-line comment blocks
15
- * @param sql The SQL string
16
- * @return The SQL string without comments
17
- * @private
18
- */
19
- _stripComments(sql) {
20
- // multiline comments
21
- sql = sql.replace(/\/\*[\s\S]*?\*\//g, '');
22
- // single line comments -- dashes
23
- sql = sql.replace(/--([\r\n]|\s+[^\r\n]+[\r\n])/g, '');
24
- // single line comments #hashes
25
- sql = sql.replace(/#[^\r\n]+[\r\n]/g, '');
26
- return sql;
27
- }
28
- /**
29
- * Before splitting into SQL clauses, extract some regex-able subQueries
30
- * @param sql The unparsed sql string
31
- * @return An array with new sql and subQueries
32
- * @private
33
- */
34
- _extractSubQueries(sql) {
35
- const subQueries = {};
36
- let i = 0;
37
- const extractor = $0 => {
38
- const placeholder = `~~SUBQUERY_${i++}~~`;
39
- subQueries[placeholder] = $0;
40
- return placeholder;
41
- };
42
- // subselect in FROM clause
43
- sql = sql.replace(/\(\s*SELECT\s+.+\)\s+AS\s+[^\s,]+/, extractor);
44
- // IF() in FROM clause
45
- sql = sql.replace(/\bIF\s*\(.+\)\s+AS\s+[^\s,]+/, extractor);
46
- // IN (SELECT *) in JOINs, WHERE or HAVING
47
- sql = sql.replace(/\bIN\s*\(\s*SELECT\s.+?\)/, extractor);
48
- return { sql, subQueries };
49
- }
50
- /**
51
- * Inject column subQueries back into this object
52
- * @param subQueries The lookup of extracted subQueries
53
- * @private
54
- */
55
- _injectSubQueries(subQueries) {
56
- const replacer = $0 => {
57
- return subQueries[$0] || $0;
58
- };
59
- const mapper = clause => {
60
- return clause.replace(/~~SUBQUERY_\d+~~/g, replacer);
61
- };
62
- this.query._columns = this.query._columns.map(replacer);
63
- this.query._joins = this.query._joins.map(mapper);
64
- this.query._wheres = this.query._wheres.map(mapper);
65
- this.query._havings = this.query._havings.map(mapper);
66
- }
67
- /**
68
- * Split SQL into clauses (used by parse())
69
- * @param sql The SQL to split
70
- * @return
71
- * @private
72
- */
73
- _split(sql) {
74
- const splitter = /(?:^|\s)(SELECT|FROM|(?:INNER|LEFT\s+OUTER|RIGHT\s+OUTER|LEFT|RIGHT|CROSS|FULL|FULL\s+OUTER)\s+JOIN|WHERE|GROUP\s+BY|HAVING|ORDER\s+BY|LIMIT|OFFSET|FETCH\s+NEXT)\b/i;
75
- return sql.split(splitter);
76
- }
77
- /**
78
- * Get a QuickSelect object representing the given SQL SELECT statement
79
- * @param rawSql The raw SQL for the SELECT statement
80
- * @return True if the SQL was parsed successfully
81
- */
82
- parse(rawSql) {
83
- const stripped = this._stripComments(rawSql);
84
- const { sql, subQueries } = this._extractSubQueries(stripped);
85
- const expressions = this._split(sql);
86
- let i = 1;
87
- while (i < expressions.length) {
88
- const rawKeyword = expressions[i++].trim();
89
- const keyword = rawKeyword.toUpperCase().replace(/\s+/g, '_');
90
- const clause = expressions[i++].trim();
91
- const handler = `_handle${keyword}`;
92
- this[handler](clause);
93
- }
94
- this._injectSubQueries(subQueries);
95
- return true;
96
- }
97
- /**
98
- * Handle SQL_CALC_FOUND_ROWS and column names
99
- * @param clause The clause after the SELECT
100
- * @private
101
- */
102
- _handleSELECT(clause) {
103
- let columns = clause.split(/s*,s*/);
104
- // now handle parenthesis expressions that contain commas
105
- let buffer = '';
106
- columns.forEach((column, i) => {
107
- if (i === 0) {
108
- const optionRegex = /^(SQL_CALC_FOUND_ROWS)\s+/i;
109
- const match = column.match(optionRegex);
110
- if (match) {
111
- this.query.option(match[1]);
112
- column = column.replace(optionRegex, '');
113
- }
114
- }
115
- if (buffer.length) {
116
- // we are in the middle of an expression containing parenthesis
117
- if (column.indexOf(')') > 0) {
118
- // we have an end parenthesis
119
- buffer += column;
120
- this.query.column(buffer.trim());
121
- buffer = '';
122
- }
123
- else {
124
- buffer += column + ',';
125
- }
126
- }
127
- else if (column.match(/\([^)]+$/)) {
128
- buffer = column + ',';
129
- }
130
- else {
131
- this.query.column(column.trim());
132
- }
133
- });
134
- }
135
- /**
136
- * Handle table names
137
- * @param clause The clause after the FROM
138
- * @private
139
- */
140
- _handleFROM(clause) {
141
- const tables = clause.split(/\s*,\s*/);
142
- tables.forEach(table => this.query.table(table));
143
- }
144
- /**
145
- * Handle INNER JOIN statements
146
- * @param clause The clause after the INNER JOIN
147
- * @private
148
- */
149
- _handleINNER_JOIN(clause) {
150
- this.query.innerJoin(clause);
151
- }
152
- /**
153
- * Handle LEFT JOIN statements
154
- * @param clause The clause after the LEFT JOIN
155
- * @private
156
- */
157
- _handleLEFT_JOIN(clause) {
158
- this.query.leftJoin(clause);
159
- }
160
- /**
161
- * Handle LEFT OUTER JOIN statements
162
- * @param clause The clause after the LEFT OUTER JOIN
163
- * @private
164
- */
165
- _handleLEFT_OUTER_JOIN(clause) {
166
- this.query.leftOuterJoin(clause);
167
- }
168
- /**
169
- * Handle RIGHT JOIN statements
170
- * @param clause The clause after the RIGHT JOIN
171
- * @private
172
- */
173
- _handleRIGHT_JOIN(clause) {
174
- this.query.rightJoin(clause);
175
- }
176
- /**
177
- * Handle RIGHT OUTER JOIN statements
178
- * @param clause The clause after the RIGHT OUTER JOIN
179
- * @private
180
- */
181
- _handleRIGHT_OUTER_JOIN(clause) {
182
- this.query.rightOuterJoin(clause);
183
- }
184
- /**
185
- * Handle CROSS JOIN statements
186
- * @param clause The clause after the CROSS JOIN
187
- * @private
188
- */
189
- _handleCROSS_JOIN(clause) {
190
- this.query.crossJoin(clause);
191
- }
192
- /**
193
- * Handle FULL JOIN statements
194
- * @param clause The clause after the FULL JOIN
195
- * @private
196
- */
197
- _handleFULL_JOIN(clause) {
198
- this.query.fullJoin(clause);
199
- }
200
- /**
201
- * Handle FULL OUTER JOIN statements
202
- * @param clause The clause after the FULL OUTER JOIN
203
- * @private
204
- */
205
- _handleFULL_OUTER_JOIN(clause) {
206
- this.query.fullOuterJoin(clause);
207
- }
208
- /**
209
- * Handle WHERE conditions
210
- * @param clause All the conditions after WHERE
211
- * @private
212
- */
213
- _handleWHERE(clause) {
214
- if (/^(1|'1'|true)$/i.test(clause)) {
215
- this.query._wheres.push(clause);
216
- }
217
- else {
218
- this._handleConditions('where', clause);
219
- }
220
- }
221
- /**
222
- * Handle HAVING statements
223
- * @param clause All the conditions after HAVING
224
- * @private
225
- */
226
- _handleHAVING(clause) {
227
- this._handleConditions('having', clause);
228
- }
229
- /**
230
- * Build a conditions list
231
- * @param type Either where or having
232
- * @param clause The expressions following the type keyword
233
- * @private
234
- */
235
- _handleConditions(type, clause) {
236
- const andGroups = clause.split(/\bAND\b/i);
237
- andGroups.forEach(andGroup => {
238
- const orPieces = andGroup.split(/\bOR\b/i).map(str => str.trim());
239
- if (orPieces.length === 1) {
240
- // no OR operators
241
- const fn = type; // either where or having
242
- this.query[fn](orPieces[0]);
243
- }
244
- else {
245
- // some OR operators
246
- // either orWhere or orHaving
247
- const orFn = type === 'where' ? 'orWhere' : 'orHaving';
248
- this.query[orFn](orPieces.map(p => [p]));
249
- }
250
- });
251
- }
252
- /**
253
- * Handle GROUP BY statements
254
- * @param clause The clauses after the GROUP BY
255
- * @private
256
- */
257
- _handleGROUP_BY(clause) {
258
- const columns = clause.split(/\s*,\s*/);
259
- columns.forEach(column => this.query.groupBy(column));
260
- }
261
- /**
262
- * Handle ORDER BY statements
263
- * @param clause The clause after the ORDER BY
264
- * @private
265
- */
266
- _handleORDER_BY(clause) {
267
- const columns = clause.split(/\s*,\s*/);
268
- columns.forEach(column => this.query.orderBy(column));
269
- }
270
- /**
271
- * Handle LIMIT statements including "LIMIT #" and "LIMIT #, #"
272
- * @param clause The clause after the LIMIT
273
- * @private
274
- */
275
- _handleLIMIT(clause) {
276
- const offsetLimit = clause.match(/^(\d+|\?|:\w+)\s*,\s*(\d+|\?|:\w+)$/);
277
- if (offsetLimit) {
278
- this.query.offset(offsetLimit[1]);
279
- this.query.limit(offsetLimit[2]);
280
- }
281
- else {
282
- clause = clause.replace(/ ROWS$/i, '');
283
- this.query.limit(clause);
284
- }
285
- }
286
- /**
287
- * Handle OFFSET statements
288
- * @param clause The number after the OFFSET
289
- * @private
290
- */
291
- _handleOFFSET(clause) {
292
- clause = clause.replace(/^(\d+) ROWS$/i, '$1');
293
- this.query.offset(clause);
294
- }
295
- /**
296
- * Handle OFFSET statements
297
- * @param clause The number after the OFFSET
298
- * @private
299
- */
300
- _handleFETCH_NEXT(clause) {
301
- clause = clause.replace(/^(\d+) ROWS ONLY$/i, '$1');
302
- this.query.limit(clause);
303
- }
304
- }
@@ -1,379 +0,0 @@
1
- export type FieldName = 'option' | 'options' | 'select' | 'column' | 'columns' | 'table' | 'tables' | 'join' | 'joins' | 'where' | 'wheres' | 'having' | 'havings' | 'groupBy' | 'groupBys' | 'orderBy' | 'orderBys' | 'limit' | 'offset' | 'page';
2
- export type EngineStyle = 'mssql' | 'mysql' | 'oracle' | 'pg';
3
- export type WhereCriteria = [string, string, any] | [string, any] | [string] | [Record<string, any>];
4
- /**
5
- * Build a select query
6
- * Class Select
7
- */
8
- export default class SelectBuilder {
9
- /**
10
- * The list of values to bind to the query
11
- * @private
12
- */
13
- _bindings: any[];
14
- /**
15
- * The list of strings to come immediately after "SELECT"
16
- * and before column names
17
- * @private
18
- */
19
- _options: string[];
20
- /**
21
- * The list of column names to select
22
- * @private
23
- */
24
- _tables: string[];
25
- /**
26
- * The list of tables in the FROM clause
27
- * @private
28
- */
29
- _columns: string[];
30
- /**
31
- * The list of JOIN strings to add
32
- * @private
33
- */
34
- _joins: string[];
35
- /**
36
- * The list of WHERE clauses to join with AND
37
- * @private
38
- */
39
- _wheres: string[];
40
- /**
41
- * The list of GROUP BY clauses to join with commas
42
- * @private
43
- */
44
- _groupBys: string[];
45
- /**
46
- * The list of HAVING clauses to join with AND
47
- * @private
48
- */
49
- _havings: string[];
50
- /**
51
- * The list of ORDER BY clauses to join with commas
52
- * @private
53
- */
54
- _orderBys: string[];
55
- /**
56
- * The LIMIT to use
57
- * @private
58
- */
59
- _limit: number;
60
- /**
61
- * The OFFSET to use
62
- * @private
63
- */
64
- _offset: number;
65
- /**
66
- * The page used to construct an OFFSET based on the LIMIT
67
- * @private
68
- */
69
- _page: number;
70
- /**
71
- * Select constructor
72
- * @param [sql] A base SQL query to parse
73
- * @param [bindings] Placeholders to bind to the query
74
- */
75
- constructor(sql?: string, bindings?: Record<string, any>);
76
- /**
77
- * Set the default database engine style (mssql, mysql, oracle, pg)
78
- * @param engine
79
- */
80
- static setDefaultEngine(engine: EngineStyle): typeof SelectBuilder;
81
- /**
82
- * Get the SQL as a pretty-printed string alongside an array of bindings
83
- * @param engine The database engine style (mssql, mysql, oracle, pg)
84
- * @return The SQL query as a string
85
- */
86
- compile({ engine, bindingIndex, }?: {
87
- engine?: EngineStyle;
88
- bindingIndex?: number;
89
- }): {
90
- sql: string;
91
- bindings: any;
92
- };
93
- _compileLIMIT(engineStyle: EngineStyle, limit: number): string;
94
- _compileOFFSET(engineStyle: EngineStyle, offset: number): string;
95
- /**
96
- * Get SQL needed to return the found rows of this query
97
- * @param engineStyle The database engine style (mssql, mysql, oracle, pg)
98
- * @param countExpr The expression to use inside the COUNT()
99
- */
100
- compileCount({ countExpr, engine, bindingIndex, }?: {
101
- countExpr?: string;
102
- engine?: EngineStyle;
103
- bindingIndex?: number;
104
- }): {
105
- sql: string;
106
- bindings: any;
107
- };
108
- /**
109
- * Get SQL needed to union this query with another
110
- * @param query The query to union
111
- * @param engine The database engine style (mssql, mysql, oracle, pg)
112
- */
113
- compileUnion(query: SelectBuilder, { engine, bindingIndex, }?: {
114
- engine?: EngineStyle;
115
- bindingIndex?: number;
116
- }): {
117
- sql: string;
118
- bindings: any[];
119
- };
120
- /**
121
- * @param [fieldOrFields] If given, reset the given component(s), otherwise reset all query components
122
- * Valid components: option, column, table, where, orWhere, having, groupBy, orderBy, limit, offset, page
123
- * @return This object
124
- */
125
- reset(fieldOrFields?: FieldName | FieldName[]): this;
126
- /**
127
- * Clone this builder object
128
- */
129
- getClone(): SelectBuilder;
130
- /**
131
- * Build a version of this query that simply returns COUNT(*)
132
- * @param [countExpr="*"] Use to specify `DISTINCT colname` if needed
133
- */
134
- getFoundRowsQuery(countExpr?: string): SelectBuilder;
135
- /**
136
- * Add an array of column names to fetch
137
- * @param columnNames The names of columns
138
- */
139
- select(columnNames: string[]): this;
140
- /**
141
- * Add an array of column names to fetch
142
- * @param columnNames The names of columns
143
- */
144
- columns(columnNames: string[]): this;
145
- /**
146
- * Add a column name to fetch
147
- * @param columnName The name of the column
148
- */
149
- column(columnName: string): this;
150
- /**
151
- * Add an option expression such as "TOP 10" or "SQL_CALC_FOUND_ROWS"
152
- * @param optionExpression Expression to go after "SELECT" and before column list
153
- */
154
- option(optionExpression: string): this;
155
- /**
156
- * Add a table to the "FROM" clause (same as .from())
157
- * @param {String} tableName The name of the table to query
158
- * @return {Select}
159
- */
160
- table(tableName: string): this;
161
- /**
162
- * Add multiple table to the "FROM" clause
163
- * @param {Array} tableNames The names of the tables to query
164
- * @return {Select}
165
- */
166
- tables(tableNames: string[]): this;
167
- /**
168
- * Add a table to the "FROM" clause (same as .table())
169
- * @param {String} tableName The name of the table to query
170
- * @return {Select}
171
- */
172
- from(tableName: string): this;
173
- /**
174
- * Add the given join type expression
175
- * @param joinType The type of join (e.g. "INNER JOIN", "LEFT JOIN", etc.)
176
- * @param expression The expression following the INNER JOIN keyword
177
- * @param bindings A list of values to bind to ? placeholders in the expression
178
- * @example
179
- * query.join('posts p ON p.id = c.post_id');
180
- * query.join('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
181
- */
182
- _addJoin(joinType: string, expression: string, bindings?: any[]): void;
183
- /**
184
- * Add a JOIN expression
185
- * @param expression The expression following the INNER JOIN keyword
186
- * @param bindings A list of values to bind to ? placeholders in the expression
187
- * @example
188
- * query.join('posts p ON p.id = c.post_id');
189
- * query.join('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
190
- */
191
- join(expression: string, bindings?: any[]): this;
192
- /**
193
- * Add a LEFT JOIN expression
194
- * @param expression The expression following the LEFT JOIN keyword
195
- * @param bindings A list of values to bind to ? placeholders in the expression
196
- * @example
197
- * query.leftJoin('posts p ON p.id = c.post_id');
198
- * query.leftJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
199
- */
200
- leftJoin(expression: string, bindings?: any[]): this;
201
- /**
202
- * Add a FULL JOIN expression
203
- * @param expression The expression following the FULL JOIN keyword
204
- * @param bindings A list of values to bind to ? placeholders in the expression
205
- * @example
206
- * query.fullJoin('posts p ON p.id = c.post_id');
207
- * query.fullJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
208
- */
209
- fullJoin(expression: string, bindings?: any[]): this;
210
- /**
211
- * Add a RIGHT JOIN expression
212
- * @param expression The expression following the RIGHT JOIN keyword
213
- * @param bindings A list of values to bind to ? placeholders in the expression
214
- * @example
215
- * query.rightJoin('posts p ON p.id = c.post_id');
216
- * query.rightJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
217
- */
218
- rightJoin(expression: string, bindings?: any[]): this;
219
- /**
220
- * Add a CROSS JOIN expression
221
- * @param expression The expression following the CROSS JOIN keyword
222
- * @param bindings A list of values to bind to ? placeholders in the expression
223
- * @example
224
- * query.crossJoin('posts p ON p.id = c.post_id');
225
- * query.crossJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
226
- */
227
- crossJoin(expression: string, bindings?: any[]): this;
228
- /**
229
- * Add an INNER JOIN expression (same as ->join())
230
- * @param expression The expression following the INNER JOIN keyword
231
- * @param bindings A list of values to bind to ? placeholders in the expression
232
- * @example
233
- * query.innerJoin('posts p ON p.id = c.post_id');
234
- * query.innerJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
235
- */
236
- innerJoin(expression: string, bindings?: any[]): this;
237
- /**
238
- * Add a LEFT OUTER JOIN expression
239
- * @param expression The expression following the LEFT OUTER JOIN keyword
240
- * @param bindings A list of values to bind to ? placeholders in the expression
241
- * @example
242
- * query.leftOuterJoin('posts p ON p.id = c.post_id');
243
- * query.leftOuterJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
244
- */
245
- leftOuterJoin(expression: string, bindings?: any[]): this;
246
- /**
247
- * Add a FULL OUTER JOIN expression
248
- * @param expression The expression following the FULL OUTER JOIN keyword
249
- * @param bindings A list of values to bind to ? placeholders in the expression
250
- * @example
251
- * query.fullOuterJoin('posts p ON p.id = c.post_id');
252
- * query.fullOuterJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
253
- */
254
- fullOuterJoin(expression: string, bindings?: any[]): this;
255
- /**
256
- * Add a RIGHT OUTER JOIN expression
257
- * @param expression The expression following the RIGHT OUTER JOIN keyword
258
- * @param bindings A list of values to bind to ? placeholders in the expression
259
- * @example
260
- * query.rightOuterJoin('posts p ON p.id = c.post_id');
261
- * query.rightOuterJoin('posts p ON p.id = c.post_id AND p.deleted_at < ?', [myDate]);
262
- */
263
- rightOuterJoin(expression: string, bindings?: any[]): this;
264
- /**
265
- * Remove a join condition with the specified table
266
- * @param table The name of the table or tables in the first part of the join statement
267
- */
268
- unjoin(table: string | string[]): this;
269
- /**
270
- * Utility function to add conditions for a clause (WHERE, HAVING)
271
- * @param collection The collection to add the clauses to (e.g. this._wheres or this._havings)
272
- * @param criteria Criteria adhering to WhereCriteria type
273
- * @example The following are equivalent
274
- * this._conditions(this._wheres, ['deleted_at IS NULL']);
275
- * this._conditions(this._wheres, ['deleted_at', null]);
276
- * this._conditions(this._wheres, ['deleted_at', '=', null]);
277
- * @example More examples
278
- * this._conditions(this._wheres, ['fname', 'LIKE', 'joe']); // `fname` LIKE 'joe'
279
- * this._conditions(this._wheres, ['fname', 'LIKE ?', 'joe']); // `fname` LIKE 'joe'
280
- * this._conditions(this._wheres, ['fname LIKE %?%', 'joe']); // `fname` LIKE '%joe%'
281
- * this._conditions(this._wheres, ['fname LIKE ?%', 'joe']); // `fname` LIKE 'joe%'
282
- * this._conditions(this._wheres, ['fname', 'LIKE ?%', 'joe']); // `fname` LIKE 'joe%'
283
- * this._conditions(this._wheres, ['price >', 10]); // `price` > 10
284
- * this._conditions(this._wheres, ['price', '>', 10]); // `price` > 10
285
- * this._conditions(this._wheres, ['price =', 10]); // `price` = 10
286
- * this._conditions(this._wheres, ['price !=', 10]); // `price` != 10
287
- * this._conditions(this._wheres, ['price', 10]); // `price` = 10
288
- * this._conditions(this._wheres, ['price', '=', 10]); // `price` = 10
289
- * this._conditions(this._wheres, ['price', '!=', 10]); // `price` != 10
290
- * this._conditions(this._wheres, ['price', 'BETWEEN', [10,20]]); // `price` BETWEEN 10 AND 20
291
- * this._conditions(this._wheres, ['price', 'NOT BETWEEN', [10,20]]); // `price` NOT BETWEEN 10 AND 20
292
- * this._conditions(this._wheres, ['price', [10,20]]); // `price` IN(10,20)
293
- * this._conditions(this._wheres, ['price', '=', [10,20]]); // `price` IN(10,20)
294
- * this._conditions(this._wheres, ['price', 'IN', [10,20]]); // `price` IN(10,20)
295
- * this._conditions(this._wheres, ['price', 'NOT IN', [10,20]]); // `price` NOT IN(10,20)
296
- */
297
- _conditions(collection: string[], criteria: WhereCriteria): this;
298
- /**
299
- * Add a group by column or expression
300
- * @param column The name of a column (or expression) to group by
301
- */
302
- groupBy(column: string): this;
303
- /**
304
- * Add WHERE clauses to conditions (See _conditions for usage)
305
- */
306
- where(...args: WhereCriteria): this;
307
- /**
308
- * Add a WHERE clause with a BETWEEN condition
309
- * @param column The column name
310
- * @param twoValueArray The two values to be between
311
- */
312
- whereBetween(column: string, twoValueArray: [any, any]): this;
313
- /**
314
- * Add a series of WHERE clauses joined by OR (See _conditions for usage)
315
- * @param conditions
316
- */
317
- _orConditions(conditions: WhereCriteria[] | Record<string, any>[] | Record<string, any>): string;
318
- /**
319
- * Add WHERE conditions to place inside an OR block (See _conditions for usage)
320
- * @param conditions A list or object where each item is an array with parameters that would be taken by where()
321
- */
322
- orWhere(conditions: WhereCriteria[] | Record<string, any>[] | Record<string, any>): this;
323
- /**
324
- * Add an OR with conditions under the HAVING clause
325
- * @param conditions A list or object where each item is an array with parameters that would be taken by having()
326
- */
327
- orHaving(conditions: WhereCriteria[] | Record<string, any>[] | Record<string, any>): this;
328
- /**
329
- * Add a HAVING condition (See _conditions for usage)
330
- */
331
- having(...args: WhereCriteria): this;
332
- /**
333
- * Add a column or expression to order by
334
- * @param column The column name or expression to sort by. Include DESC or prefix with - to sort descending
335
- * @param [direction] The direction to sort by (ASC or DESC)
336
- * @example
337
- * query.sortField('modified_at'); // ORDER BY modified_at
338
- * query.sortField('-modified_at'); // ORDER BY modified_at DESC
339
- * query.sortField('COUNT(*)'); // ORDER BY COUNT(*)
340
- * query.sortField('COUNT(*) DESC'); // ORDER BY COUNT(*) DESC
341
- */
342
- orderBy(column: string, direction?: 'ASC' | 'DESC'): this;
343
- /**
344
- * Sort by the given column, with a map of columns to translate
345
- * @param fieldName The file name such as "created_at" or "-created_at" for descending
346
- * @param [mapNames] Column names to translate from field to column expression
347
- * @example
348
- * query.sortField('-modified_at'); // ORDER BY modified_at DESC
349
- * query.sortField('-created', {'created': 'created_at'}); // ORDER BY created_at DESC
350
- */
351
- sortField(fieldName: string, mapNames?: Record<string, string>): this;
352
- /**
353
- * Check to see if the given string is 0 or all digits not starting with 0
354
- * @param string The input string
355
- * @private
356
- */
357
- _isEntirelyDigits(string: string): boolean;
358
- /**
359
- * Check to see if the given string is all digits
360
- * @param string The input string
361
- * @private
362
- */
363
- _isEntirelyDigitsNoZeros(string: string): boolean;
364
- /**
365
- * Limit results to the given number
366
- * @param max The number to limit by (placeholder string or integer greater than 0)
367
- */
368
- limit(max: number | string): this;
369
- /**
370
- * Fetch results from the given offset
371
- * @param number The offset (placeholder string or integer greater than or equal to 0)
372
- */
373
- offset(number: number | string): this;
374
- /**
375
- * Set the offset based on the limit with the given page number
376
- * @param number The page number (integer greater than 0)
377
- */
378
- page(number: number | string): this;
379
- }