implement GRIDs
This commit is contained in:
+36
-1
@@ -6,7 +6,7 @@ namespace App\Models;
|
||||
* Row in a data table
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $data - JSONB
|
||||
* @property string $data - JSONB, always containing _grid
|
||||
*/
|
||||
class Row extends BaseModel
|
||||
{
|
||||
@@ -16,4 +16,39 @@ class Row extends BaseModel
|
||||
|
||||
protected $guarded = [];
|
||||
public $timestamps = false;
|
||||
|
||||
public function getGridAttribute() {
|
||||
return $this->data->_grid;
|
||||
}
|
||||
|
||||
public function setGridAttribute($value) {
|
||||
$this->data->_grid = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a single Global Row ID, application-unique.
|
||||
*
|
||||
* GRIDs are used to uniquely identify existing or proposed new rows,
|
||||
* and are preserved after row modifications, to ensure change proposals have
|
||||
* a clear target.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function allocateGRID()
|
||||
{
|
||||
return \DB::selectOne("SELECT nextval('global_row_id_seq') AS grid;")->grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a block of Global Row IDs, application-unique.
|
||||
*
|
||||
* @see Row::allocateGRID()
|
||||
*
|
||||
* @return int[] first and last
|
||||
*/
|
||||
public static function allocateGRIDs($count)
|
||||
{
|
||||
$last = \DB::selectOne("SELECT multi_nextval('global_row_id_seq', ?) AS last_grid;", [$count])->last_grid;
|
||||
return [$last - $count + 1, $last];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user