Skip to content

Commit

Permalink
Merge pull request #10 from mychidarko/next
Browse files Browse the repository at this point in the history
Add DB Url support
  • Loading branch information
mychidarko authored Aug 3, 2023
2 parents 5b66375 + f3d74b6 commit 6d7cad8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"php",
"framework"
],
"homepage": "https://leafphp.netlify.app/#/",
"homepage": "https://leafphp.dev/modules/db/",
"type": "library",
"license": "MIT",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function connect(
$dbtype = $this->config('dbtype');

$connection = new \PDO(
$this->dsn(),
$this->config('dbUrl') ?? $this->dsn(),
$dbtype === 'sqlite' ? null : $this->config('username'),
$dbtype === 'sqlite' ? null : $this->config('password'),
array_merge(
Expand Down
8 changes: 4 additions & 4 deletions tests/mysql/connect.test.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

beforeAll(function () {
$pdo = new \PDO('mysql:host=sql7.freemysqlhosting.net;dbname=sql7600346', 'sql7600346', 'l87WSttrMv');
$pdo = new \PDO('mysql:host=eu-cdbr-west-03.cleardb.net;dbname=heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17');

$query = '
DROP TABLE IF EXISTS `test`;
Expand All @@ -24,7 +24,7 @@

try {
$db = new \Leaf\Db();
expect($db->connect('sql7.freemysqlhosting.net', 'sql7600346', 'sql7600346', 'l87WSttrMv'))
expect($db->connect('eu-cdbr-west-03.cleardb.net', 'heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17'))
->toBeInstanceOf(\PDO::class);
$db->close();

Expand All @@ -38,7 +38,7 @@
it('inserts dummy user into `test` table', function () {
$success = false;
$db = new \Leaf\Db();
$db->connect('sql7.freemysqlhosting.net', 'sql7600346', 'sql7600346', 'l87WSttrMv');
$db->connect('eu-cdbr-west-03.cleardb.net', 'heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17');

try {
$db->insert('test')
Expand Down Expand Up @@ -67,7 +67,7 @@

it('selects dummy user from `test` table', function () {
$db = new \Leaf\Db();
$db->connect('sql7.freemysqlhosting.net', 'sql7600346', 'sql7600346', 'l87WSttrMv');
$db->connect('eu-cdbr-west-03.cleardb.net', 'heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17');

$user = $db->select('test')
->where('name', 'Name')
Expand Down
6 changes: 3 additions & 3 deletions tests/mysql/leaf-builder.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

it('orders results in ascending order', function () {
$db = new \Leaf\Db();
$db->connect('sql7.freemysqlhosting.net', 'sql7600346', 'sql7600346', 'l87WSttrMv');
$db->connect('eu-cdbr-west-03.cleardb.net', 'heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17');

$users = $db->select('test')->orderBy("created_at", "asc")->all();

Expand All @@ -12,7 +12,7 @@

it('orders results in descending order', function () {
$db = new \Leaf\Db();
$db->connect('sql7.freemysqlhosting.net', 'sql7600346', 'sql7600346', 'l87WSttrMv');
$db->connect('eu-cdbr-west-03.cleardb.net', 'heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17');

$users = $db->select('test')->orderBy("created_at", "desc")->all();

Expand All @@ -22,7 +22,7 @@

it('orders by dummy name and count', function () {
$db = new \Leaf\Db();
$db->connect('sql7.freemysqlhosting.net', 'sql7600346', 'sql7600346', 'l87WSttrMv');
$db->connect('eu-cdbr-west-03.cleardb.net', 'heroku_fb1311a639bb407', 'b9607a8a6d5ebb', 'cc589b17');

$data = $db->select('test', 'name, COUNT(*)')->groupBy("created_at")->all();

Expand Down

0 comments on commit 6d7cad8

Please sign in to comment.