Skip to content

Commit 1a57448

Browse files
committed
feat: add warnings for non-normal behaviour
1 parent ba63ccd commit 1a57448

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/docs/database/builder.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Although you can write raw queries using the `query()` method, there's no fun in
66

77
This is something you would usually want to do outside of your application, but there are a few rare cases where you might want to create a database from within your application. Leaf DB provides a `create()` method that allows you to do just that.
88

9-
```php
9+
```php:no-line-numbers
1010
db()->create('dbname')->execute();
1111
```
1212

@@ -26,7 +26,7 @@ db()
2626

2727
Dropping a database is the opposite of creating one. It deletes the database and all its contents. Leaf DB provides a `drop()` method that allows you to do this.
2828

29-
```php
29+
```php:no-line-numbers
3030
db()->drop('dbname')->execute();
3131
```
3232

@@ -40,13 +40,13 @@ This method needs the name of the table you want to add data to, like "users", a
4040

4141
Here's an example:
4242

43-
```php
43+
```php:no-line-numbers
4444
db()->insert('users')->params(['username' => 'mychi']);
4545
```
4646

4747
This is equivalent to the following SQL query:
4848

49-
```sql
49+
```sql:no-line-numbers
5050
INSERT INTO users (username) VALUES ('mychi')
5151
```
5252

@@ -89,17 +89,19 @@ db()->insert('users')->params(['username' => 'mychi'])->execute();
8989
$lastId = db()->lastInsertId();
9090
```
9191

92+
Note that this may not work correctly if your database uses non-auto-incrementing IDs like UUIDs or ULIDs.
93+
9294
## Reading data from a database
9395

9496
Reading from a database means retrieving data stored in a table. Leaf DB provides a `select()` method that allows you to build a query to retrieve data from a table. The `select()` method takes the name of the table you want to read from as its argument.
9597

96-
```php
98+
```php:no-line-numbers
9799
db()->select('users')->all();
98100
```
99101

100102
This will return all the rows in the users table. You can also specify the columns you want to return by passing them as the second argument to the `select()` method.
101103

102-
```php
104+
```php:no-line-numbers
103105
db()->select('users', 'name, created_at')->all();
104106
```
105107

@@ -172,7 +174,7 @@ db()
172174

173175
Almost every database table has an `id` column that uniquely identifies each row. Leaf DB provides a `find()` method that allows you to retrieve a row by its `id`.
174176

175-
```php
177+
```php:no-line-numbers
176178
db()->select('users')->find(1);
177179
```
178180

@@ -209,7 +211,7 @@ Deleting data from a database works by finding the data you want to delete and t
209211

210212
Here's an example:
211213

212-
```php
214+
```php:no-line-numbers
213215
db()->delete('users')->execute(); // careful now 🙂
214216
```
215217

@@ -259,6 +261,10 @@ if ($success) {
259261

260262
This is useful especially when you have a set of queries that rely on third party influence.
261263

264+
::: warning Rollback not working
265+
Transactions will only work correctly if your queries use Leaf DB. This is because your queries need to use the same database connection to be able to be rolled back. This means you can't use transactions with your Leaf MVC models at the moment, but this may change in the future.
266+
:::
267+
262268
## Hiding columns from results
263269

264270
Sometimes you might want to hide certain columns from the results of a query. For instance, you might want to hide the password column from the results of a query on the users table. Leaf DB provides a `hide()` method that allows you to do this.

0 commit comments

Comments
 (0)