Skip to content

Commit

Permalink
Schema builder added
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-darock committed May 3, 2022
1 parent 78dc4dc commit 40dd469
Show file tree
Hide file tree
Showing 22 changed files with 6,837 additions and 96 deletions.
39 changes: 11 additions & 28 deletions admin/controller/common/nexus.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Aweb\Nexus\Support\Str;
use Aweb\Nexus\Validator;
use Aweb\Nexus\Db;
use Aweb\Nexus\Schema;
use Aweb\Nexus\Database\Schema\Blueprint;
use Aweb\Nexus\Support\Updater;

class ControllerCommonNexus extends Controller {
Expand Down Expand Up @@ -63,8 +65,9 @@ public function update()
public function tests()
{



// transactions https://laravel.com/docs/5.8/database
// rollback ?!??!
// pre( DB::table('setting')->count());
// DB::transaction(function () {
// DB::table('setting')->insert(['code' => 'test_db']);
Expand All @@ -79,35 +82,15 @@ public function tests()
// DB::commit();
// DB::rollBack();
// pre( DB::table('setting')->count());
// /**
// * Start a new database transaction.
// *
// * @return void
// */
// public function beginTransaction();

// /**
// * Commit the active database transaction.
// *
// * @return void
// */
// public function commit();

// /**
// * Rollback the active database transaction.
// *
// * @return void
// */
// public function rollBack();

// /**
// * Get the number of active transactions.
// *
// * @return int
// */
// public function transactionLevel();


// Schema::create('flights', function (Blueprint $table) {
// $table->bigIncrements('id');
// $table->string('name');
// $table->string('airline');
// $table->timestamps();
// });
// Schema::drop('flights');

// Db::table('setting')->insert([
// 'code' => 'test_db',
Expand Down
140 changes: 76 additions & 64 deletions system/library/aweb/nexus/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
use Illuminate\Contracts\Events\Dispatcher;
use Aweb\Nexus\Database\Events\QueryExecuted;
use Doctrine\DBAL\Connection as DoctrineConnection;
use Doctrine\DBAL\Driver\PDOMySql\Driver as DoctrineDriver;
use Aweb\Nexus\Database\Query\Processors\Processor;
use Aweb\Nexus\Database\Query\Builder as QueryBuilder;
use Aweb\Nexus\Database\Schema\Builder as SchemaBuilder;
use Aweb\Nexus\Database\Query\Grammars\Grammar as QueryGrammar;
use Aweb\Nexus\Nexus;
use Aweb\Nexus\Support\Str;
use Aweb\Nexus\Database\Schema\Grammars\MySqlGrammar;

class Connection implements ConnectionInterface
{
Expand Down Expand Up @@ -202,20 +204,20 @@ protected function getDefaultQueryGrammar()
*
* @return void
*/
// public function useDefaultSchemaGrammar()
// {
// $this->schemaGrammar = $this->getDefaultSchemaGrammar();
// }
public function useDefaultSchemaGrammar()
{
$this->schemaGrammar = $this->getDefaultSchemaGrammar();
}

/**
* Get the default schema grammar instance.
*
* @return \Aweb\Nexus\Database\Schema\Grammars\Grammar
*/
// protected function getDefaultSchemaGrammar()
// {
// //
// }
protected function getDefaultSchemaGrammar()
{
return new MySqlGrammar;
}

/**
* Set the query post processor to the default implementation.
Expand All @@ -237,19 +239,29 @@ protected function getDefaultPostProcessor()
return new Processor;
}

/**
* Get the Doctrine DBAL driver.
*
* @return \Doctrine\DBAL\Driver\PDOMySql\Driver
*/
protected function getDoctrineDriver()
{
return new DoctrineDriver;
}

/**
* Get a schema builder instance for the connection.
*
* @return \Aweb\Nexus\Database\Schema\Builder
*/
// public function getSchemaBuilder()
// {
// if (is_null($this->schemaGrammar)) {
// $this->useDefaultSchemaGrammar();
// }
public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
$this->useDefaultSchemaGrammar();
}

// return new SchemaBuilder($this);
// }
return new SchemaBuilder($this);
}

/**
* Begin a fluent query against a database table.
Expand Down Expand Up @@ -873,60 +885,60 @@ public function recordsHaveBeenModified($value = true)
}
}

// /**
// * Is Doctrine available?
// *
// * @return bool
// */
// public function isDoctrineAvailable()
// {
// return class_exists('Doctrine\DBAL\Connection');
// }
/**
* Is Doctrine available?
*
* @return bool
*/
public function isDoctrineAvailable()
{
return class_exists('Doctrine\DBAL\Connection');
}

// /**
// * Get a Doctrine Schema Column instance.
// *
// * @param string $table
// * @param string $column
// * @return \Doctrine\DBAL\Schema\Column
// */
// public function getDoctrineColumn($table, $column)
// {
// $schema = $this->getDoctrineSchemaManager();
/**
* Get a Doctrine Schema Column instance.
*
* @param string $table
* @param string $column
* @return \Doctrine\DBAL\Schema\Column
*/
public function getDoctrineColumn($table, $column)
{
$schema = $this->getDoctrineSchemaManager();

// return $schema->listTableDetails($table)->getColumn($column);
// }
return $schema->listTableDetails($table)->getColumn($column);
}

// /**
// * Get the Doctrine DBAL schema manager for the connection.
// *
// * @return \Doctrine\DBAL\Schema\AbstractSchemaManager
// */
// public function getDoctrineSchemaManager()
// {
// return $this->getDoctrineDriver()->getSchemaManager($this->getDoctrineConnection());
// }
/**
* Get the Doctrine DBAL schema manager for the connection.
*
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
public function getDoctrineSchemaManager()
{
return $this->getDoctrineDriver()->getSchemaManager($this->getDoctrineConnection());
}

// /**
// * Get the Doctrine DBAL database connection instance.
// *
// * @return \Doctrine\DBAL\Connection
// */
// public function getDoctrineConnection()
// {
// if (is_null($this->doctrineConnection)) {
// $driver = $this->getDoctrineDriver();

// $this->doctrineConnection = new DoctrineConnection(array_filter([
// 'pdo' => $this->getPdo(),
// 'dbname' => $this->getConfig('database'),
// 'driver' => $driver->getName(),
// 'serverVersion' => $this->getConfig('server_version'),
// ]), $driver);
// }
/**
* Get the Doctrine DBAL database connection instance.
*
* @return \Doctrine\DBAL\Connection
*/
public function getDoctrineConnection()
{
if (is_null($this->doctrineConnection)) {
$driver = $this->getDoctrineDriver();

// return $this->doctrineConnection;
// }
$this->doctrineConnection = new DoctrineConnection(array_filter([
'pdo' => $this->getPdo(),
'dbname' => $this->getConfig('database'),
'driver' => $driver->getName(),
'serverVersion' => $this->getConfig('server_version'),
]), $driver);
}

return $this->doctrineConnection;
}

/**
* Get the current PDO connection.
Expand Down
Loading

0 comments on commit 40dd469

Please sign in to comment.