Skip to content

Commit

Permalink
fix: set database driver in querybuilder class
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseekn committed Oct 31, 2021
1 parent 87c1ce8 commit f31c211
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions core/Database/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ class QueryBuilder

protected static function setTable(string $name)
{
if (config('app.env') === 'test') {
if (config('testing.database.driver') === 'sqlite') {
return config('database.table_prefix') . $name;
}

return config('database.name') .config('testing.database.suffix') . '.' . config('database.table_prefix') . $name;
}

if (config('database.driver') === 'sqlite') {
return config('database.table_prefix') . $name;
}

$db = config('app.env') !== 'test' ? config('database.name')
: config('database.name') . config('testing.database.suffix');

return $db . '.' . config('database.table_prefix') . $name;
return config('database.name') . '.' . config('database.table_prefix') . $name;
}

public static function table(string $name): self
Expand Down Expand Up @@ -195,8 +200,10 @@ public function column(string $name, string $type): self

public function autoIncrement(): self
{
$driver = config('app.env') === 'test' ? $driver = config('testing.database.driver') : config('database.driver');

self::$query = rtrim(self::$query, ', ');
self::$query .= config('database.driver') === 'mysql' ? ' AUTO_INCREMENT, ' : ' AUTOINCREMENT, ';
self::$query .= $driver === 'mysql' ? ' AUTO_INCREMENT, ' : ' AUTOINCREMENT, ';
return $this;
}

Expand Down Expand Up @@ -270,8 +277,10 @@ public function onDeleteSetNull(): self
*/
public function migrate()
{
$driver = config('app.env') === 'test' ? $driver = config('testing.database.driver') : config('database.driver');

if (config('database.timestamps')) {
if (config('database.driver') === 'mysql') {
if ($driver === 'mysql') {
self::$query .= " created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
} else {
self::$query .= " created_at TIMESTAMP NOT NULL DEFAULT (datetime(CURRENT_TIMESTAMP, 'localtime')), updated_at TIMESTAMP NOT NULL DEFAULT (datetime(CURRENT_TIMESTAMP, 'localtime')))";
Expand All @@ -280,7 +289,7 @@ public function migrate()

if (self::$query[-1] !== ')') self::$query .= ')';

if (config('database.driver') === 'mysql') {
if ($driver === 'mysql') {
self::$query .= " ENGINE='" . config('database.mysql.engine') . "'";
}

Expand Down

0 comments on commit f31c211

Please sign in to comment.