\Phinx\Db\AdapterPostgresAdapter

Phinx PDO Adapter.

Summary

Methods
Properties
Constants
__construct()
setOptions()
getOptions()
hasOption()
getOption()
setInput()
getInput()
setOutput()
getOutput()
setSchemaTableName()
getSchemaTableName()
setConnection()
getConnection()
setCommandStartTime()
getCommandStartTime()
startCommandTimer()
endCommandTimer()
writeCommand()
connect()
disconnect()
execute()
query()
fetchRow()
fetchAll()
insert()
getVersions()
getVersionLog()
migrated()
toggleBreakpoint()
resetAllBreakpoints()
hasSchemaTable()
createSchemaTable()
getAdapterType()
getColumnTypes()
isValidColumnType()
castToBool()
hasTransactions()
beginTransaction()
commitTransaction()
rollbackTransaction()
quoteSchemaName()
quoteTableName()
quoteColumnName()
hasTable()
createTable()
renameTable()
dropTable()
getColumns()
hasColumn()
addColumn()
renameColumn()
changeColumn()
dropColumn()
hasIndex()
hasIndexByName()
addIndex()
dropIndex()
dropIndexByName()
hasForeignKey()
addForeignKey()
dropForeignKey()
getSqlType()
getPhinxType()
createDatabase()
hasDatabase()
dropDatabase()
createSchema()
hasSchema()
dropSchema()
dropAllSchemas()
getAllSchemas()
No public properties found
INT_SMALL
getIndexes()
getForeignKeys()
getDefaultValueDefinition()
getColumnSqlDefinition()
getColumnCommentSqlDefinition()
getIndexSqlDefinition()
getForeignKeySqlDefinition()
isArrayType()
$options
$input
$output
$schemaTableName
$connection
$commandStartTime
$columnsWithComments
N/A
getSchemaName()
No private properties found
N/A

Constants

INT_SMALL

INT_SMALL = 65535

Properties

$options

$options : array

Type

array

$schemaTableName

$schemaTableName : string

Type

string

$connection

$connection : \PDO

Type

\PDO

$commandStartTime

$commandStartTime : float

Type

float

$columnsWithComments

$columnsWithComments : array

Columns with comments

Type

array

Methods

__construct()

__construct(array  $options, \think\console\Input  $input = null, \think\console\Output  $output = null) 

Class Constructor.

Parameters

array $options

Options

\think\console\Input $input

Input Interface

\think\console\Output $output

Output Interface

setOptions()

setOptions(array  $options) : \Phinx\Db\Adapter\AdapterInterface

Set adapter configuration options.

Parameters

array $options

Returns

\Phinx\Db\Adapter\AdapterInterface

getOptions()

getOptions() : array

Get all adapter options.

Returns

array

hasOption()

hasOption(string  $name) : boolean

Check if an option has been set.

Parameters

string $name

Returns

boolean

getOption()

getOption(string  $name) : mixed

Get a single adapter option, or null if the option does not exist.

Parameters

string $name

Returns

mixed

setSchemaTableName()

setSchemaTableName(string  $schemaTableName) : \Phinx\Db\Adapter\PdoAdapter

Sets the schema table name.

Parameters

string $schemaTableName

Schema Table Name

Returns

\Phinx\Db\Adapter\PdoAdapter

getSchemaTableName()

getSchemaTableName() : string

Gets the schema table name.

Returns

string

setConnection()

setConnection(\PDO  $connection) : \Phinx\Db\Adapter\AdapterInterface

Sets the database connection.

Parameters

\PDO $connection

Connection

Returns

\Phinx\Db\Adapter\AdapterInterface

getConnection()

getConnection() : \PDO

Gets the database connection

Returns

\PDO

setCommandStartTime()

setCommandStartTime(integer  $time) : \Phinx\Db\Adapter\AdapterInterface

Sets the command start time

Parameters

integer $time

Returns

\Phinx\Db\Adapter\AdapterInterface

getCommandStartTime()

getCommandStartTime() : integer

Gets the command start time

Returns

integer

startCommandTimer()

startCommandTimer() : void

Start timing a command.

endCommandTimer()

endCommandTimer() : void

Stop timing the current command and write the elapsed time to the output.

writeCommand()

writeCommand(string  $command, array  $args = array()) : void

Write a Phinx command to the output.

Parameters

string $command

Command Name

array $args

Command Args

connect()

connect() : void

Initializes the database connection.

disconnect()

disconnect() : void

Closes the database connection.

execute()

execute(string  $sql) : integer

Executes a SQL statement and returns the number of affected rows.

Parameters

string $sql

SQL

Returns

integer

query()

query(string  $sql) : array

Executes a SQL statement and returns the result as an array.

Parameters

string $sql

SQL

Returns

array

fetchRow()

fetchRow(string  $sql) : array

Executes a query and returns only one row as an array.

Parameters

string $sql

SQL

Returns

array

fetchAll()

fetchAll(string  $sql) : array

Executes a query and returns an array of rows.

Parameters

string $sql

SQL

Returns

array

insert()

insert(\Phinx\Db\Table  $table, array  $row) : void

Inserts data into a table.

Parameters

\Phinx\Db\Table $table

where to insert data

array $row

getVersions()

getVersions() : array

Get all migrated version numbers.

Returns

array

getVersionLog()

getVersionLog() : array

Get all migration log entries, indexed by version number.

Returns

array

migrated()

migrated(\Phinx\Migration\MigrationInterface  $migration, string  $direction, integer  $startTime, integer  $endTime) : \Phinx\Db\Adapter\AdapterInterface

Records a migration being run.

Parameters

\Phinx\Migration\MigrationInterface $migration

Migration

string $direction

Direction

integer $startTime

Start Time

integer $endTime

End Time

Returns

\Phinx\Db\Adapter\AdapterInterface

resetAllBreakpoints()

resetAllBreakpoints() : integer

Reset all migration breakpoints.

Returns

integer —

The number of breakpoints reset

hasSchemaTable()

hasSchemaTable() : boolean

Does the schema table exist?

Returns

boolean

createSchemaTable()

createSchemaTable() : void

Creates the schema table.

getAdapterType()

getAdapterType() : string

Returns the adapter type.

Returns

string

getColumnTypes()

getColumnTypes() : array

Returns an array of the supported Phinx column types.

Returns

array

isValidColumnType()

isValidColumnType(\Phinx\Db\Table\Column  $column) : boolean

Checks that the given column is of a supported type.

Parameters

\Phinx\Db\Table\Column $column

Returns

boolean

castToBool()

castToBool(mixed  $value) : mixed

Cast a value to a boolean appropriate for the adapter.

Parameters

mixed $value

The value to be cast

Returns

mixed

hasTransactions()

hasTransactions() : boolean

Does the adapter support transactions?

Returns

boolean

beginTransaction()

beginTransaction() : void

Begin a transaction.

commitTransaction()

commitTransaction() : void

Commit a transaction.

rollbackTransaction()

rollbackTransaction() : void

Rollback a transaction.

quoteSchemaName()

quoteSchemaName(string  $schemaName) : string

Quotes a schema name for use in a query.

Parameters

string $schemaName

Schema Name

Returns

string

quoteTableName()

quoteTableName(string  $tableName) : string

Quotes a table name for use in a query.

Parameters

string $tableName

Table Name

Returns

string

quoteColumnName()

quoteColumnName(string  $columnName) : string

Quotes a column name for use in a query.

Parameters

string $columnName

Table Name

Returns

string

hasTable()

hasTable(string  $tableName) : boolean

Checks to see if a table exists.

Parameters

string $tableName

Table Name

Returns

boolean

createTable()

createTable(\Phinx\Db\Table  $table) : void

Creates the specified database table.

Parameters

\Phinx\Db\Table $table

Table

renameTable()

renameTable(string  $tableName,   $newTableName) : void

Renames the specified database table.

Parameters

string $tableName

Table Name

$newTableName

dropTable()

dropTable(string  $tableName) : void

Drops the specified database table.

Parameters

string $tableName

Table Name

getColumns()

getColumns(string  $tableName) : array<mixed,\Phinx\Db\Table\Column>

Returns table columns

Parameters

string $tableName

Table Name

Returns

array<mixed,\Phinx\Db\Table\Column>

hasColumn()

hasColumn(string  $tableName, string  $columnName,   $options = array()) : boolean

Checks to see if a column exists.

Parameters

string $tableName

Table Name

string $columnName

Column Name

$options

Returns

boolean

addColumn()

addColumn(\Phinx\Db\Table  $table, \Phinx\Db\Table\Column  $column) : void

Adds the specified column to a database table.

Parameters

\Phinx\Db\Table $table

Table

\Phinx\Db\Table\Column $column

Column

renameColumn()

renameColumn(string  $tableName, string  $columnName, string  $newColumnName) : void

Renames the specified column.

Parameters

string $tableName

Table Name

string $columnName

Column Name

string $newColumnName

New Column Name

changeColumn()

changeColumn(string  $tableName, string  $columnName, \Phinx\Db\Table\Column  $newColumn) : \Phinx\Db\Table

Change a table column type.

Parameters

string $tableName

Table Name

string $columnName

Column Name

\Phinx\Db\Table\Column $newColumn

New Column

Returns

\Phinx\Db\Table

dropColumn()

dropColumn(string  $tableName, string  $columnName) : void

Drops the specified column.

Parameters

string $tableName

Table Name

string $columnName

Column Name

hasIndex()

hasIndex(string  $tableName, mixed  $columns) : boolean

Checks to see if an index exists.

Parameters

string $tableName

Table Name

mixed $columns

Column(s)

Returns

boolean

hasIndexByName()

hasIndexByName(string  $tableName, string  $indexName) : boolean

Checks to see if an index specified by name exists.

Parameters

string $tableName

Table Name

string $indexName

Returns

boolean

addIndex()

addIndex(\Phinx\Db\Table  $table, \Phinx\Db\Table\Index  $index) : void

Adds the specified index to a database table.

Parameters

\Phinx\Db\Table $table

Table

\Phinx\Db\Table\Index $index

Index

dropIndex()

dropIndex(string  $tableName, mixed  $columns) : void

Drops the specified index from a database table.

Parameters

string $tableName
mixed $columns

Column(s)

dropIndexByName()

dropIndexByName(string  $tableName, string  $indexName) : void

Drops the index specified by name from a database table.

Parameters

string $tableName
string $indexName

hasForeignKey()

hasForeignKey(string  $tableName, array<mixed,string>  $columns, string  $constraint = null) : boolean

Checks to see if a foreign key exists.

Parameters

string $tableName
array<mixed,string> $columns

Column(s)

string $constraint

Constraint name

Returns

boolean

addForeignKey()

addForeignKey(\Phinx\Db\Table  $table, \Phinx\Db\Table\ForeignKey  $foreignKey) : void

Adds the specified foreign key to a database table.

Parameters

\Phinx\Db\Table $table
\Phinx\Db\Table\ForeignKey $foreignKey

dropForeignKey()

dropForeignKey(string  $tableName, array<mixed,string>  $columns, string  $constraint = null) : void

Drops the specified foreign key from a database table.

Parameters

string $tableName
array<mixed,string> $columns

Column(s)

string $constraint

Constraint name

getSqlType()

getSqlType(string  $type, integer  $limit = null) : string

Converts the Phinx logical type to the adapter's SQL type.

Parameters

string $type
integer $limit

Returns

string

getPhinxType()

getPhinxType(string  $sqlType) 

Returns Phinx type by SQL type

Parameters

string $sqlType

SQL type

createDatabase()

createDatabase(string  $name, array  $options = array()) : void

Creates a new database.

Parameters

string $name

Database Name

array $options

Options

hasDatabase()

hasDatabase(  $databaseName) : boolean

Checks to see if a database exists.

Parameters

$databaseName

Returns

boolean

dropDatabase()

dropDatabase(string  $name) : void

Drops the specified database.

Parameters

string $name

Database Name

createSchema()

createSchema(string  $schemaName = 'public') : void

Creates the specified schema.

Parameters

string $schemaName

Schema Name

hasSchema()

hasSchema(string  $schemaName) : boolean

Checks to see if a schema exists.

Parameters

string $schemaName

Schema Name

Returns

boolean

dropSchema()

dropSchema(string  $schemaName) : void

Drops the specified schema table.

Parameters

string $schemaName

Schema name

dropAllSchemas()

dropAllSchemas() : void

Drops all schemas.

getAllSchemas()

getAllSchemas() : array

Returns schemas.

Returns

array

getIndexes()

getIndexes(string  $tableName) : array

Get an array of indexes from a particular table.

Parameters

string $tableName

Table Name

Returns

array

getForeignKeys()

getForeignKeys(string  $tableName) : array

Get an array of foreign keys from a particular table.

Parameters

string $tableName

Table Name

Returns

array

getDefaultValueDefinition()

getDefaultValueDefinition(mixed  $default) : string

Get the defintion for a `DEFAULT` statement.

Parameters

mixed $default

Returns

string

getColumnSqlDefinition()

getColumnSqlDefinition(\Phinx\Db\Table\Column  $column) : string

Gets the PostgreSQL Column Definition for a Column object.

Parameters

\Phinx\Db\Table\Column $column

Column

Returns

string

getColumnCommentSqlDefinition()

getColumnCommentSqlDefinition(\Phinx\Db\Table\Column  $column, string  $tableName) : string

Gets the PostgreSQL Column Comment Defininition for a column object.

Parameters

\Phinx\Db\Table\Column $column

Column

string $tableName

Table name

Returns

string

getIndexSqlDefinition()

getIndexSqlDefinition(\Phinx\Db\Table\Index  $index, string  $tableName) : string

Gets the PostgreSQL Index Definition for an Index object.

Parameters

\Phinx\Db\Table\Index $index

Index

string $tableName

Table name

Returns

string

getForeignKeySqlDefinition()

getForeignKeySqlDefinition(\Phinx\Db\Table\ForeignKey  $foreignKey, string  $tableName) : string

Gets the MySQL Foreign Key Definition for an ForeignKey object.

Parameters

\Phinx\Db\Table\ForeignKey $foreignKey
string $tableName

Table name

Returns

string

isArrayType()

isArrayType(string  $columnType) : boolean

Check if the given column is an array of a valid type.

Parameters

string $columnType

Returns

boolean

getSchemaName()

getSchemaName() : string

Gets the schema name.

Returns

string