Skip to content

Medoo v2.6.0 - PHPStan Level 10

Latest

Choose a tag to compare

@catfan catfan released this 22 Aug 04:27

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 RETURNING support for insert() 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 socket option.
    • Empty host and database attributes are no longer added to the DSN.
  • Improved PostgreSQL id() behavior.
    • Uses the cached value returned by RETURNING when available.
    • Returns null when LASTVAL() is not yet defined for the current session.
    • Keeps explicit sequence-name support through id($sequence).
  • Added validation for charset and MySQL collation values before using them in SET NAMES.
  • Applied PostgreSQL charset settings when an existing PDO connection is supplied.
  • Improved PDO result type handling for fetchAll() and lastInsertId().

Resolved Issues

  • Fixed invalid SQL generated from empty IN and NOT IN conditions.
[
    '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 mariadb alias.