LegacyKey class abstract final

Keys for tables that have no sequence, where Laravel code writes MAX(id) + 1. Two requests doing that at once read the same maximum.

final id = await LegacyKey.insert('kandidat', {'nama': nama});

Each read waits for the writer before it until that writer commits: an advisory lock on PostgreSQL, a row lock on MySQL and MariaDB, the write lock on SQLite. MAX(id) ... FOR UPDATE is not valid SQL, and MySQL's GET_LOCK cannot outlast a transaction on a pooled connection.

That only binds code that uses this class. Laravel writing to the same table takes no lock, so insert tries again when the key is taken. On PostgreSQL this needs the default READ COMMITTED: a snapshot from an older statement cannot see the writer it waited for.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

insert(String table, Map<String, Object?> values, {String column = 'id', String? connection}) → Future<int>
Inserts values under the next key of table and returns the key.
next(String table, {String column = 'id', String? connection}) → Future<int>
The next key of table. The key is held only until the transaction ends, so this must run inside one, with the insert: outside, it would be free for anyone again before the caller used it.