Skip to content

Commit

Permalink
v5.0.0 updates (#8)
Browse files Browse the repository at this point in the history
* Updated calculation of query durations

* v5.0.0 updates

* Updated documentation
  • Loading branch information
robinsonjohn authored Sep 17, 2024
1 parent 5a62563 commit 1e2c9e5
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 131 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities

## [5.0.0] - 2024.09.16

### Added

- Added `setQueryTime` method.

### Changed

- Updated method for calculating query durations to be more accurate.
- Updated `getQueryTime` and `getTotalQueries` methods to accept a specific database name.
- Updated `DbFactory::create` method to not require a specific `default` database.

### Removed

- Removed concept of "default" and "current" database in favor of simply using "current".
- Removed `getDefaultConnectionName` method.

## [4.0.1] - 2024.09.10

### Fixed
Expand Down
66 changes: 34 additions & 32 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Once an instance is created, you can begin using Simple PDO.
- [useConnection](#useconnection)
- [getConnection](#getconnection)
- [getCurrentConnection](#getcurrentconnection)
- [getDefaultConnectionName](#getdefaultconnectionname)
- [getCurrentConnectionName](#getcurrentconnectionname)
- [getConnectionNames](#getconnectionnames)
- [connectionExists](#connectionexists)
Expand All @@ -53,6 +52,7 @@ Once an instance is created, you can begin using Simple PDO.
- [getLastParameters](#getlastparameters)
- [rowCount](#rowcount)
- [lastInsertId](#lastinsertid)
- [setQueryTime](#setquerytime)
- [getQueryTime](#getquerytime)
- [getTotalQueries](#gettotalqueries)

Expand All @@ -68,8 +68,7 @@ Add a PDO instance.

- `$pdo` (PDO)
- `$db_name` (string): Name must be unique
- `$make_current = false` (bool): Use this connection for the next query only
- `$make_default = false` (bool): Use this connection for each subsequent query
- `$make_current = false` (bool): Use this connection for all subsequent queries

**Returns:**

Expand Down Expand Up @@ -97,13 +96,11 @@ try {

**Description:**

Set given database name as current for the next query only.
After the next query, the current database will automatically revert to the default database.
Use a given database connection for all subsequent queries.

**Parameters:**

- `$db_name` (string)
- `$make_default = false` (bool)

**Returns:**

Expand Down Expand Up @@ -181,33 +178,11 @@ $pdo = $db->getCurrentConnection();

<hr />

### getDefaultConnectionName

**Description:**

Returns name of the default database.

**Parameters:**

- None

**Returns:**

- (string)

**Example:**

```php
echo $db->getDefaultConnectionName();
```

<hr />

### getCurrentConnectionName

**Description:**

Returns name of the database currently being used.
Returns name of the current database connection.

**Parameters:**

Expand Down Expand Up @@ -686,15 +661,42 @@ echo $db->lastInsertId();

<hr />

### setQueryTime

**Description:**

Add a query time to be tracked using `getQueryTime` and `getTotalQueries`.
This is helpful to track queries using the [query builder](query-builder.md).

**Parameters:**

- `$db_name` (string)
- `$duration = 0` (float): Microseconds as float

**Returns:**

- (void)

**Example:**

```php
$start_time = microtime(true);

// Perform a query outside the Db class

$db->setQueryTime('backup', microtime(true) - $start_time);
```

### getQueryTime

**Description:**

Returns the total time elapsed in seconds for all queries executed for the current database.
Returns the total time elapsed in seconds for all queries executed for a given database.

**Parameters:**

- `$decimals = 3` (int): Number of decimal points to return
- `$db_name = ''` (string): Leaving this parameter blank will return the time elapsed for all database connections

**Returns:**

Expand All @@ -712,11 +714,11 @@ echo $db->getQueryTime();

**Description:**

Returns the total number of queries executed for the current database.
Returns the total number of queries executed for a given database.

**Parameters:**

- None
- `$db_name = ''` (string): Leaving this parameter blank will return the total queries for all database connections

**Returns:**

Expand Down
5 changes: 2 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ use Bayfront\SimplePdo\Exceptions\SimplePDOException;

$config = [
'primary' => [ // Connection name
'default' => true, // One connection on the array must be defined as default
'adapter' => 'MySql', // Adapter to use
'host' => 'DB_HOST',
'port' => 3306,
Expand Down Expand Up @@ -74,5 +73,5 @@ try {
```

The array keys define the connection names.
Each name must be unique.
One connection must be defined as `default`, and each connection must specify a valid adapter.
Each name must be unique, and each connection must specify a valid adapter.
The first listed connection name in the array will be set as the current database.
Loading

0 comments on commit 1e2c9e5

Please sign in to comment.