Skip to content

Commit

Permalink
Organize Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Dec 6, 2024
1 parent 58436e3 commit c2ef12e
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,26 @@ $conn = \ByJG\AnyDataset\Db\Factory::getDbInstance("mysql://root:[email protected]

- [Getting Started](docs/getting-started.md)
- [Basic Query and Update](docs/basic-query.md)
- [Sql Statement Object](docs/sqlstatement.md)
- [Cache results](docs/cache.md)
- [Database Transaction](docs/transaction.md)
- [Load Balance and Connection Pooling](docs/load-balance.md)
- [Database Helper](docs/helper.md)
- [Filtering the Query](docs/iteratorfilter.md)

## Advanced Topics

- [Passing Parameters to PDODriver](docs/parameters.md)
- [Generic PDO Driver](docs/generic-pdo-driver.md)
- [Running Tests](docs/tests.md)
- [Getting an Iterator from an existing PDO Statament](docs/pdostatement.md)

## Database Specifics

- [MySQL](docs/mysql.md)
- [Oracle](docs/oracle.md)
- [SQLServer](docs/sqlserver.md)
- [Literal PDO Connection String](docs/literal-pdo-driver.md)


## Install
Expand Down
4 changes: 4 additions & 0 deletions docs/basic-query.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 2
---

# Basics

## Basic Query
Expand Down
4 changes: 4 additions & 0 deletions docs/cache.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 4
---

# Cache results

You can easily cache your results to speed up the results of long queries;
Expand Down
4 changes: 4 additions & 0 deletions docs/generic-pdo-driver.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 10
---

# Generic PDO configuration

If you want to use a PDO driver that is not mapped into the `anydataset-db` library you can use the generic PDO driver.
Expand Down
4 changes: 4 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 1
---

# Getting Started

## 1. Install the ByJG AnyDatasetDB library
Expand Down
4 changes: 4 additions & 0 deletions docs/helper.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 7
---

# Helper - DbFunctions

AnyDataset has a helper `ByJG\AnyDataset\Db\DbFunctionsInterface` that can be return some specific data based on the database connection.
Expand Down
4 changes: 4 additions & 0 deletions docs/iteratorfilter.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 8
---

# Using IteratorFilter

`IteratorFilter` is a class that helps you to create a filter to be used in the Iterator.
Expand Down
17 changes: 14 additions & 3 deletions docs/literal-pdo-driver.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
---
sidebar_position: 16
---

# Literal PDO configuration

If you want to use a PDO driver, and it requires special parameters don't fit well using the URI model you can use the literal object.
It will allow you to pass the PDO connection string directly.
If you want to use a PDO driver and this driver is not available in the AnyDatasetDB or and it requires special
parameters don't fit well
using the URI model you can use the literal object.

The `PdoLiteral` object uses the PDO connection string instead of the URI model.

Example:

Expand All @@ -11,6 +18,10 @@ Example:
$literal = new \ByJG\AnyDataset\Db\PdoLiteral("sqlite::memory:");
```

The general rule is use the string as you would use in the PDO constructor.
Drawbacks:

* You can't use the `Factory::getDbInstance` to get the database instance. You need to use the `PdoLiteral` object
directly.
* The DBHelper won't work with the `PdoLiteral` object.


4 changes: 4 additions & 0 deletions docs/load-balance.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 6
---

# Load balancing

The API have support for connection load balancing, connection pooling and persistent connection.
Expand Down
4 changes: 4 additions & 0 deletions docs/mysql.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 13
---

# Driver: MySQL

The connection string can have special attributes to connect using SSL.
Expand Down
4 changes: 4 additions & 0 deletions docs/oracle.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 14
---

# Driver: Oracle

The Oracle Driver don't use the PHP PDO Driver. Instead, uses the OCI library.
Expand Down
4 changes: 4 additions & 0 deletions docs/parameters.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 9
---

# Passing Parameters to PDODriver

You can pass parameter directly to the PDODriver by adding to the connection string a query parameter with the value.
Expand Down
37 changes: 37 additions & 0 deletions docs/pdostatement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
sidebar_position: 12
---

# Using a PDO Statement

If you have a PDO Statement created outside the AnyDatasetDB library,
you can use it to create an iterator.

```php
<?php
$pdo = new PDO('sqlite::memory:');
$stmt = $pdo->prepare('select * from info where id = :id');
$stmt->execute(['id' => 1]);

$iterator = $this->dbDriver->getIterator($stmt);
$this->assertEquals(
[
[ 'id'=> 1, 'iduser' => 1, 'number' => 10.45, 'property' => 'xxx'],
],
$iterator->toArray()
);
```

Note:

* Although you can use a PDO Statement, it is recommended to use the
`SqlStatement` or `DbDriverInterface` to get the Query.
* Use this feature with legacy code or when you have a specific need to use a PDO Statement.

## Benefits

You can integrate the AnyDatasetDB library with your legacy code and get the benefits of the library
as for example the standard `GenericIterator`



4 changes: 4 additions & 0 deletions docs/sqlserver.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 15
---

# Driver: Microsoft SQL Server

There are two Drivers to connect to Microsoft SQL Server.
Expand Down
4 changes: 4 additions & 0 deletions docs/sqlstatement.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 3
---

# SQL Statement

The SQL Statement is a class to abstract the SQL query from the database.
Expand Down
4 changes: 4 additions & 0 deletions docs/tests.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 11
---

# Running Unit tests

## Unit Tests (no DBConnection)
Expand Down
4 changes: 4 additions & 0 deletions docs/transaction.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
sidebar_position: 5
---

# Database Transaction

## Basics
Expand Down
16 changes: 16 additions & 0 deletions tests/PdoSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,20 @@ public function testCachedResults2()
$iterator->toArray()
);
}

public function testPDOStatement()
{
$pdo = $this->dbDriver->getDbConnection();
$stmt = $pdo->prepare('select * from info where id = :id');
$stmt->execute(['id' => 1]);

$iterator = $this->dbDriver->getIterator($stmt);
$this->assertEquals(
[
['id' => 1, 'iduser' => 1, 'number' => 10.45, 'property' => 'xxx'],
],
$iterator->toArray()
);

}
}

0 comments on commit c2ef12e

Please sign in to comment.