示例#1
0
 /**
  * Compile a rename column command.
  *
  * @param  \Nova\Database\Schema\Blueprint  $blueprint
  * @param  \Nova\Support\Fluent  $command
  * @param  \Nova\Database\Connection  $connection
  * @return array
  */
 public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
 {
     $schema = $connection->getDoctrineSchemaManager();
     $table = $this->getTablePrefix() . $blueprint->getTable();
     $column = $connection->getDoctrineColumn($table, $command->from);
     $tableDiff = $this->getRenamedDiff($blueprint, $command, $column, $schema);
     return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
 }
示例#2
0
 /**
  * Append the character set specifications to a command.
  *
  * @param  string  $sql
  * @param  \Nova\Database\Connection  $connection
  * @return string
  */
 protected function compileCreateEncoding($sql, Connection $connection)
 {
     if (!is_null($charset = $connection->getConfig('charset'))) {
         $sql .= ' default character set ' . $charset;
     }
     if (!is_null($collation = $connection->getConfig('collation'))) {
         $sql .= ' collate ' . $collation;
     }
     return $sql;
 }
 /**
  * Execute a Closure within a transaction.
  *
  * @param  \Closure  $callback
  * @return mixed
  *
  * @throws \Exception
  */
 public function transaction(Closure $callback)
 {
     if ($this->getDriverName() == 'sqlsrv') {
         return parent::transaction($callback);
     }
     $this->pdo->exec('BEGIN TRAN');
     try {
         $result = $callback($this);
         $this->pdo->exec('COMMIT TRAN');
     } catch (\Exception $e) {
         $this->pdo->exec('ROLLBACK TRAN');
         throw $e;
     }
     return $result;
 }
 /**
  * Execute a Closure within a transaction.
  *
  * @param  \Closure  $callback
  * @return mixed
  *
  * @throws \Exception
  */
 public function transaction(Closure $callback)
 {
     if ($this->getDriverName() == 'sqlsrv') {
         return parent::transaction($callback);
     }
     $this->pdo->exec('BEGIN TRAN');
     // We'll simply execute the given callback within a try / catch block
     // and if we catch any exception we can rollback the transaction
     // so that none of the changes are persisted to the database.
     try {
         $result = $callback($this);
         $this->pdo->exec('COMMIT TRAN');
     } catch (\Exception $e) {
         $this->pdo->exec('ROLLBACK TRAN');
         throw $e;
     }
     return $result;
 }
 /**
  * Retrieve a user by the given credentials.
  *
  * @param  array  $credentials
  * @return \Nova\Auth\UserInterface|null
  */
 public function retrieveByCredentials(array $credentials)
 {
     // First we will add each credential element to the query as a where clause.
     // Then we can execute the query and, if we found a user, return it in a
     // generic "user" object that will be utilized by the Guard instances.
     $query = $this->conn->table($this->table);
     foreach ($credentials as $key => $value) {
         if (!str_contains($key, 'password')) {
             $query->where($key, $value);
         }
     }
     // Now we are ready to execute the query to see if we have an user matching
     // the given credentials. If not, we will just return nulls and indicate
     // that there are no matching users for these given credential arrays.
     $user = $query->first();
     if (!is_null($user)) {
         return new GenericUser((array) $user);
     }
 }
示例#6
0
 /**
  * Get a query builder for the cache table.
  *
  * @return \Nova\Database\Query\Builder
  */
 protected function table()
 {
     return $this->connection->table($this->table);
 }
示例#7
0
 /**
  * Compile a drop column command.
  *
  * @param  \Nova\Database\Schema\Blueprint  $blueprint
  * @param  \Nova\Support\Fluent  $command
  * @param  \Nova\Database\Connection  $connection
  * @return array
  */
 public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
 {
     $schema = $connection->getDoctrineSchemaManager();
     $tableDiff = $this->getDoctrineTableDiff($blueprint, $schema);
     foreach ($command->columns as $name) {
         $column = $connection->getDoctrineColumn($blueprint->getTable(), $name);
         $tableDiff->removedColumns[$name] = $column;
     }
     return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
 }
示例#8
0
 /**
  * Prepare the read write mode for database connection instance.
  *
  * @param  \Nova\Database\Connection  $connection
  * @param  string  $type
  * @return \Nova\Database\Connection
  */
 protected function setPdoForType(Connection $connection, $type = null)
 {
     if ($type == 'read') {
         $connection->setPdo($connection->getReadPdo());
     } else {
         if ($type == 'write') {
             $connection->setReadPdo($connection->getPdo());
         }
     }
     return $connection;
 }
示例#9
0
 /**
  * Get the column listing for a given table.
  *
  * @param  string  $table
  * @return array
  */
 public function getColumnListing($table)
 {
     $table = $this->connection->getTablePrefix() . $table;
     $results = $this->connection->select($this->grammar->compileColumnExists($table));
     return $this->connection->getPostProcessor()->processColumnListing($results);
 }
示例#10
0
 /**
  * Create a raw database expression.
  *
  * @param  mixed  $value
  * @return \Nova\Database\Query\Expression
  */
 public function raw($value)
 {
     return $this->connection->raw($value);
 }
示例#11
0
 /**
  * Create a new database query
  *
  * @return \Database\Query
  */
 public function newQuery()
 {
     return $this->connection->table($this->table);
 }
 /**
  * Get a fresh query builder instance for the table.
  *
  * @return \Nova\Database\Query\Builder
  */
 protected function getQuery()
 {
     return $this->connection->table($this->table);
 }