Skip to content

Commit decc88f

Browse files
committed
feat: add instructions for mvc
1 parent bcaa865 commit decc88f

File tree

1 file changed

+50
-17
lines changed

1 file changed

+50
-17
lines changed

src/docs/database/index.md

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,28 @@ Databases are essential for most applications, as they help you store and retrie
5252

5353
## Leaf MVC + DB
5454

55-
<div class="grid md:grid-cols-2 gap-4">
55+
Leaf's DB module is great for building simple queries, especially when you are using Leaf as a micro-framework. However, if you are building a full-fledged application using Leaf MVC, you can take advantage of the powerful models and schema files which make it easy to interact with your database.
56+
57+
Leaf MVC configures everything for you out of the box, so you just need to define your database schema using the schema files and create models to represent your database tables. You can then use the models to perform CRUD operations on your database without writing any SQL queries.
58+
59+
<div class="grid md:grid-cols-3 gap-4">
5660
<div
5761
class="w-full relative text-white overflow-hidden rounded-3xl flex shadow-lg"
5862
>
5963
<div
6064
class="w-full flex md:flex-col bg-gradient-to-br from-pink-500 to-rose-500"
6165
>
6266
<div
63-
class="sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6 xl:p-8"
67+
class="sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6"
6468
>
65-
<p class="font-medium text-rose-100 text-shadow mb-4">
66-
Models are a powerful way to interact with your database using an object-oriented approach, which also makes your code more readable and maintainable.
69+
<p class="font-semibold text-sm text-rose-100 text-shadow mb-4">
70+
Schema files allow you to define the structure of your database tables in a simple and intuitive way.
6771
</p>
6872
<Button
6973
as="a"
70-
href="/docs/database/models"
74+
href="/docs/database/files"
7175
class="mt-auto bg-rose-900 hover:!bg-rose-900 !text-white bg-opacity-50 hover:bg-opacity-75 transition-colors duration-200 rounded-xl font-bold py-2 px-4 inline-flex"
72-
>Check out models</Button
76+
>Create your schema</Button
7377
>
7478
</div>
7579
<!-- <div
@@ -82,17 +86,46 @@ Databases are essential for most applications, as they help you store and retrie
8286
class="absolute bottom-0 left-0 right-0 h-20 bg-gradient-to-t from-rose-500 hidden sm:block"
8387
></div>
8488
</div>
89+
<div
90+
class="w-full relative text-white overflow-hidden rounded-3xl flex shadow-lg"
91+
>
92+
<div
93+
class="w-full flex md:flex-col bg-gradient-to-br from-green-500 to-blue-500"
94+
>
95+
<div
96+
class="sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6"
97+
>
98+
<p class="font-semibold text-sm text-blue-100 text-shadow mb-4">
99+
Models are a powerful way to interact with your database using an object-oriented approach.
100+
</p>
101+
<Button
102+
as="a"
103+
href="/docs/database/models"
104+
class="mt-auto bg-blue-900 hover:!bg-blue-900 !text-white bg-opacity-50 hover:bg-opacity-75 transition-colors duration-200 rounded-xl font-bold py-2 px-4 inline-flex"
105+
>Check out models</Button
106+
>
107+
</div>
108+
<!-- <div
109+
class="relative md:pl-6 xl:pl-8 hidden sm:block"
110+
>
111+
Hello
112+
</div> -->
113+
</div>
114+
<div
115+
class="absolute bottom-0 left-0 right-0 h-20 bg-gradient-to-t from-blue-500 hidden sm:block"
116+
></div>
117+
</div>
85118
<div
86119
class="w-full relative text-white overflow-hidden rounded-3xl flex shadow-lg"
87120
>
88121
<div
89122
class="w-full flex md:flex-col bg-gradient-to-br from-yellow-400 to-orange-500"
90123
>
91124
<div
92-
class="sm:max-w-sm sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6 xl:p-8"
125+
class="sm:max-w-sm sm:flex-none md:w-auto md:flex-auto flex flex-col items-start relative z-10 p-6"
93126
>
94-
<p class="font-medium text-amber-100 text-shadow mb-4">
95-
You can use Leaf DB to build and run queries that don't fit into a model. Everything has been configured to work out of the box, so you can start querying your database right away.
127+
<p class="font-semibold text-sm text-amber-100 text-shadow mb-4">
128+
You can use Leaf DB to build and run queries that don't fit into a model, without any config.
96129
</p>
97130
<Button
98131
as="a"
@@ -117,7 +150,7 @@ Databases are essential for most applications, as they help you store and retrie
117150

118151
The first step to using a database is to create a connection. It's like opening a door to the database, allowing you to interact with it. Here's how you can connect to a database using Leaf:
119152

120-
```php
153+
```php:no-line-numbers
121154
db()->connect([
122155
'dbtype' => '...',
123156
'charset' => '...',
@@ -135,7 +168,7 @@ Here are some examples of how you can connect to different databases:
135168

136169
::: code-group
137170

138-
```php [MySQL]
171+
```php:no-line-numbers [MySQL]
139172
db()->connect([
140173
'host' => '127.0.0.1',
141174
'username' => 'root',
@@ -144,7 +177,7 @@ db()->connect([
144177
]);
145178
```
146179

147-
```php [PostgreSQL]
180+
```php:no-line-numbers [PostgreSQL]
148181
db()->connect([
149182
'dbtype' => 'pgsql',
150183
'host' => '127.0.0.1',
@@ -155,7 +188,7 @@ db()->connect([
155188
]);
156189
```
157190

158-
```php [SQLite]
191+
```php:no-line-numbers [SQLite]
159192
db()->connect([
160193
'dbtype' => 'sqlite',
161194
'dbname' => 'db.sqlite',
@@ -170,7 +203,7 @@ Leaf DB will not connect to your database until you run a query. This means that
170203

171204
Some applications may need to connect to multiple databases for things like queues and logs, and Leaf DB allows you to keep multiple connections open and query them independently. Here's how you can connect to multiple databases:
172205

173-
```php
206+
```php:no-line-numbers
174207
db()->addConnections([
175208
'conn1' => [
176209
'dbtype' => '...',
@@ -185,7 +218,7 @@ db()->addConnections([
185218

186219
The `addConnections()` method takes an array of connection details for your databases as its first argument and the default connection name as its second argument. You can then switch between connections using the `useConnection()` method:
187220

188-
```php
221+
```php:no-line-numbers
189222
db('conn2')->select('users')->all();
190223
```
191224

@@ -203,7 +236,7 @@ $users = db()->query('SELECT * FROM users')->all();
203236

204237
The `query()` method takes an SQL query that you want to execute as its argument. You can then use the query builder methods to modify your query. For example, you can bind values to your query using the `bind()` method:
205238

206-
```php
239+
```php:no-line-numbers
207240
db()
208241
->query('SELECT * FROM users WHERE id = ?')
209242
->bind('1')
@@ -232,7 +265,7 @@ This will return an array of all the users in the database that match the query.
232265

233266
If you only want to get one result, you can use the `fetchObj()` or `fetchAssoc()` method. For example, you can run a query like this:
234267

235-
```php
268+
```php:no-line-numbers
236269
$user = db()
237270
->query('SELECT * FROM users WHERE id = ?')
238271
->bind('1')

0 commit comments

Comments
 (0)