Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArekX committed Sep 1, 2024
1 parent 085645e commit 53e4cd0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
3 changes: 0 additions & 3 deletions docs/custom-drivers.md

This file was deleted.

41 changes: 40 additions & 1 deletion docs/drivers/mysql.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# MySQL Driver

In progress...
MySQL driver is a driver for MySQL database. It uses PDO to connect to the database and execute queries.

# Usage

To use MySQL driver you need to create a new instance of `MySQLDriver` and pass it into `QueryRunner`:

```php
use ArekX\PQL\Drivers\Pdo\MySql\MySqlDriver;
use ArekX\PQL\Drivers\Pdo\MySql\MySqlQueryBuilder;
use ArekX\PQL\QueryRunner;


$driver = MySqlDriver::create([
'dsn' => 'mysql:host=127.0.0.1;dbname=your_database',
'username' => 'username',
'password' => 'password',
]);

$builder = new MySqlQueryBuilder();

// Create a runner for your driver and builder, this should be done once in your application
$runner = QueryRunner::create($driver, $builder);
```

Driver handles the PDO connection to the database and executes the compiled queries.
Builder is used to compile the queries into a format that the driver can understand.
Runner is used to execute the queries and fetch the results.

# Running a query

To run a query you need to create a query object and pass it into the runner.
Lets do a simple select query to get all users from the database:

```php
use function \ArekX\PQL\Sql\{select, all};

$query = select('*')->from('user')->where(all(['is_active' => 1]));

$results = $runner->fetchAll($query); // Results are returned here.
```
7 changes: 0 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ Following systems are supported:

* [MySQL](drivers/mysql.md) - MySQL database via PDO

### Custom drivers

Drivers which are implemented are not limited to Relational Database Systems meaning other drivers
can be easily implemented for non-database or no-sql database systems like Redis, ElasticSearch, MongoDB, etc.

For implementing a custom driver see [here](custom-drivers.md).

## Testing

After installing the dependencies run `composer test`
Expand Down

0 comments on commit 53e4cd0

Please sign in to comment.