Skip to content

Commit 5361ce4

Browse files
committed
refactor(database): rename toSql to compile in query builders
1 parent bb63945 commit 5361ce4

File tree

9 files changed

+32
-32
lines changed

9 files changed

+32
-32
lines changed

packages/database/src/Builder/QueryBuilders/CountQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public function bind(mixed ...$bindings): self
8080
}
8181

8282
/**
83-
* Returns the SQL statement without the bindings.
83+
* Compile the query to a SQL statement without the bindings.
8484
*/
85-
public function toSql(): ImmutableString
85+
public function compile(): ImmutableString
8686
{
8787
return $this->build()->compile();
8888
}

packages/database/src/Builder/QueryBuilders/DeleteQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function bind(mixed ...$bindings): self
6969
}
7070

7171
/**
72-
* Returns the SQL statement without the bindings.
72+
* Compile the query to a SQL statement without the bindings.
7373
*/
74-
public function toSql(): ImmutableString
74+
public function compile(): ImmutableString
7575
{
7676
return $this->build()->compile();
7777
}

packages/database/src/Builder/QueryBuilders/InsertQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public function execute(mixed ...$bindings): ?PrimaryKey
7474
}
7575

7676
/**
77-
* Returns the SQL statement without the bindings.
77+
* Compile the query to a SQL statement without the bindings.
7878
*/
79-
public function toSql(): ImmutableString
79+
public function compile(): ImmutableString
8080
{
8181
return $this->build()->compile();
8282
}

packages/database/src/Builder/QueryBuilders/SelectQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ public function bind(mixed ...$bindings): self
284284
}
285285

286286
/**
287-
* Returns the SQL statement without the bindings.
287+
* Compile the query to a SQL statement without the bindings.
288288
*/
289-
public function toSql(): ImmutableString
289+
public function compile(): ImmutableString
290290
{
291291
return $this->build()->compile();
292292
}

packages/database/src/Builder/QueryBuilders/UpdateQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ public function bind(mixed ...$bindings): self
111111
}
112112

113113
/**
114-
* Returns the SQL statement without the bindings.
114+
* Compile the query to a SQL statement without the bindings.
115115
*/
116-
public function toSql(): ImmutableString
116+
public function compile(): ImmutableString
117117
{
118118
return $this->build()->compile();
119119
}

tests/Integration/Database/Builder/CountQueryBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function test_multiple_where_raw(): void
157157
->whereRaw('author_id = ?', 1)
158158
->whereRaw('OR author_id = ?', 2)
159159
->whereRaw('AND author_id <> NULL')
160-
->toSql();
160+
->compile();
161161

162162
$expected = 'SELECT COUNT(*) AS `count` FROM `books` WHERE title = ? AND author_id = ? OR author_id = ? AND author_id <> NULL';
163163

@@ -170,7 +170,7 @@ public function test_multiple_where(): void
170170
->count()
171171
->where('title', 'a')
172172
->where('author_id', 1)
173-
->toSql();
173+
->compile();
174174

175175
$expected = 'SELECT COUNT(*) AS `count` FROM `books` WHERE books.title = ? AND books.author_id = ?';
176176

tests/Integration/Database/Builder/DeleteQueryBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function test_multiple_where_raw(): void
114114
->whereRaw('author_id = ?', 1)
115115
->whereRaw('OR author_id = ?', 2)
116116
->whereRaw('AND author_id <> NULL')
117-
->toSql();
117+
->compile();
118118

119119
$expected = 'DELETE FROM `books` WHERE title = ? AND author_id = ? OR author_id = ? AND author_id <> NULL';
120120

@@ -127,7 +127,7 @@ public function test_multiple_where(): void
127127
->delete()
128128
->where('title', 'a')
129129
->where('author_id', 1)
130-
->toSql();
130+
->compile();
131131

132132
$expected = 'DELETE FROM `books` WHERE books.title = ? AND books.author_id = ?';
133133

tests/Integration/Database/Builder/SelectQueryBuilderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function test_multiple_where(): void
7575
->whereRaw('author_id = ?', 1)
7676
->whereRaw('OR author_id = ?', 2)
7777
->whereRaw('AND author_id <> NULL')
78-
->toSql();
78+
->compile();
7979

8080
$expected = 'SELECT * FROM `books` WHERE title = ? AND author_id = ? OR author_id = ? AND author_id <> NULL';
8181

@@ -88,7 +88,7 @@ public function test_multiple_where_field(): void
8888
->select()
8989
->where('title', 'a')
9090
->where('author_id', 1)
91-
->toSql();
91+
->compile();
9292

9393
$expected = 'SELECT * FROM `books` WHERE books.title = ? AND books.author_id = ?';
9494

@@ -199,17 +199,17 @@ public function test_order_by_sql_generation(): void
199199
{
200200
$this->assertSameWithoutBackticks(
201201
expected: 'SELECT * FROM `books` ORDER BY `title` ASC',
202-
actual: query('books')->select()->orderBy('title')->toSql(),
202+
actual: query('books')->select()->orderBy('title')->compile(),
203203
);
204204

205205
$this->assertSameWithoutBackticks(
206206
expected: 'SELECT * FROM `books` ORDER BY `title` DESC',
207-
actual: query('books')->select()->orderBy('title', Direction::DESC)->toSql(),
207+
actual: query('books')->select()->orderBy('title', Direction::DESC)->compile(),
208208
);
209209

210210
$this->assertSameWithoutBackticks(
211211
expected: 'SELECT * FROM `books` ORDER BY title DESC NULLS LAST',
212-
actual: query('books')->select()->orderByRaw('title DESC NULLS LAST')->toSql(),
212+
actual: query('books')->select()->orderByRaw('title DESC NULLS LAST')->compile(),
213213
);
214214
}
215215

@@ -421,7 +421,7 @@ public function test_select_query_execute_with_relations(): void
421421

422422
public function test_eager_loads_combined_with_manual_loads(): void
423423
{
424-
$query = AWithEager::select()->with('b.c')->toSql();
424+
$query = AWithEager::select()->with('b.c')->compile();
425425

426426
$this->assertSameWithoutBackticks(
427427
'SELECT a.id AS `a.id`, a.b_id AS `a.b_id`, b.id AS `b.id`, b.c_id AS `b.c_id`, c.id AS `b.c.id`, c.name AS `b.c.name` FROM `a` LEFT JOIN b ON b.id = a.b_id LEFT JOIN c ON c.id = b.c_id',
@@ -434,7 +434,7 @@ public function test_group_by(): void
434434
$sql = query('authors')
435435
->select()
436436
->groupBy('name')
437-
->toSql();
437+
->compile();
438438

439439
$expected = 'SELECT * FROM authors GROUP BY name';
440440

@@ -446,7 +446,7 @@ public function test_having(): void
446446
$sql = query('authors')
447447
->select()
448448
->having('name = ?', 'Brent')
449-
->toSql();
449+
->compile();
450450

451451
$expected = 'SELECT * FROM authors HAVING name = ?';
452452

tests/Integration/Database/Builder/UpdateQueryBuilderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function test_multiple_where(): void
252252
->whereRaw('author_id = ?', 1)
253253
->whereRaw('OR author_id = ?', 2)
254254
->whereRaw('AND author_id <> NULL')
255-
->toSql();
255+
->compile();
256256

257257
$expected = 'UPDATE `books` SET title = ? WHERE title = ? AND author_id = ? OR author_id = ? AND author_id <> NULL';
258258

@@ -267,7 +267,7 @@ public function test_multiple_where_field(): void
267267
)
268268
->where('title', 'a')
269269
->where('author_id', 1)
270-
->toSql();
270+
->compile();
271271

272272
$expected = 'UPDATE `books` SET title = ? WHERE books.title = ? AND books.author_id = ?';
273273

@@ -321,7 +321,7 @@ public function test_update_with_where_in(): void
321321
$sql = query('books')
322322
->update(title: 'Updated Book')
323323
->whereIn('id', [1, 2, 3])
324-
->toSql();
324+
->compile();
325325

326326
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`id` IN (?,?,?)';
327327

@@ -333,7 +333,7 @@ public function test_update_with_where_not_in(): void
333333
$sql = query('books')
334334
->update(title: 'Updated Book')
335335
->whereNotIn('author_id', [1, 2])
336-
->toSql();
336+
->compile();
337337

338338
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`author_id` NOT IN (?,?)';
339339

@@ -345,7 +345,7 @@ public function test_update_with_where_null(): void
345345
$sql = query('books')
346346
->update(title: 'Updated Book')
347347
->whereNull('author_id')
348-
->toSql();
348+
->compile();
349349

350350
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`author_id` IS NULL';
351351

@@ -357,7 +357,7 @@ public function test_update_with_where_not_null(): void
357357
$sql = query('books')
358358
->update(title: 'Updated Book')
359359
->whereNotNull('author_id')
360-
->toSql();
360+
->compile();
361361

362362
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`author_id` IS NOT NULL';
363363

@@ -369,7 +369,7 @@ public function test_update_with_where_between(): void
369369
$sql = query('books')
370370
->update(title: 'Updated Book')
371371
->whereBetween('id', 1, 100)
372-
->toSql();
372+
->compile();
373373

374374
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`id` BETWEEN ? AND ?';
375375

@@ -381,7 +381,7 @@ public function test_update_with_where_not_between(): void
381381
$sql = query('books')
382382
->update(title: 'Updated Book')
383383
->whereNotBetween('id', 1, 10)
384-
->toSql();
384+
->compile();
385385

386386
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`id` NOT BETWEEN ? AND ?';
387387

@@ -394,7 +394,7 @@ public function test_update_with_or_where_in(): void
394394
->update(title: 'Updated Book')
395395
->whereIn('id', [1, 2])
396396
->orWhereIn('author_id', [10, 20])
397-
->toSql();
397+
->compile();
398398

399399
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`id` IN (?,?) OR `books`.`author_id` IN (?,?)';
400400

@@ -406,7 +406,7 @@ public function test_update_captures_primary_key_for_relations_with_convenience_
406406
$sql = query(Book::class)
407407
->update(title: 'Updated Book')
408408
->whereIn('id', [5])
409-
->toSql();
409+
->compile();
410410

411411
$expected = 'UPDATE `books` SET `title` = ? WHERE `books`.`id` IN (?)';
412412

0 commit comments

Comments
 (0)