New Features
- Added portable identity primary key syntax for
create().
$database->create('account', [
'@id',
'email' => [
'VARCHAR(255)',
'NOT NULL',
'UNIQUE'
]
]);The @column syntax defines an auto-generated integer primary key. Custom column names are also supported.
$database->create('account', [
'@account_id',
'name' => [
'VARCHAR(100)',
'NOT NULL'
]
]);Medoo automatically converts the identity definition for each database:
| Database | Identity Definition |
|---|---|
| MySQL / MariaDB | BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY |
| PostgreSQL | BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY |
| SQLite | INTEGER PRIMARY KEY AUTOINCREMENT |
| MSSQL | BIGINT IDENTITY(1,1) PRIMARY KEY |
| Oracle | NUMBER(19) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY |
| Sybase | BIGINT IDENTITY PRIMARY KEY |
Only one identity column can be defined per table. Invalid identity names, duplicate identity definitions, and conflicts with regular column definitions will throw an InvalidArgumentException.
PostgreSQL identity columns require PostgreSQL 10 or later. Oracle identity columns require Oracle Database 12c or later.
- Added PostgreSQL
RETURNINGsupport forinsert()when the primary key is provided.
$database->insert('account', [
'email' => 'foo@example.com'
], 'id');
$id = $database->id();This provides reliable inserted IDs even when triggers use other sequences. Multi-row inserts return the ID of the last inserted row.
Improvements
- Medoo now adopts PHPStan level 10 rules.
- Improved PostgreSQL DSN generation.
- Added PostgreSQL Unix socket support through the
socketoption. - Empty
hostanddatabaseattributes are no longer added to the DSN.
- Added PostgreSQL Unix socket support through the
- Improved PostgreSQL
id()behavior.- Uses the cached value returned by
RETURNINGwhen available. - Returns
nullwhenLASTVAL()is not yet defined for the current session. - Keeps explicit sequence-name support through
id($sequence).
- Uses the cached value returned by
- Added validation for
charsetand MySQLcollationvalues before using them inSET NAMES. - Applied PostgreSQL charset settings when an existing PDO connection is supplied.
- Improved PDO result type handling for
fetchAll()andlastInsertId().
Resolved Issues
- Fixed invalid SQL generated from empty
INandNOT INconditions.
[
'id' => []
]
// WHERE 1 = 0[
'id[!]' => []
]
// WHERE 1 = 1- Fixed identifier quoting for single and multiple columns in
JOIN ... USING (...). - Fixed PostgreSQL Unix socket connections being ignored.
- Fixed PostgreSQL inserted IDs being affected by sequences used inside triggers.
- Fixed PostgreSQL
id()throwing an exception before a sequence was used in the current session. - Fixed database type normalization in test cases, including the
mariadbalias.