sunaoka / laravel-postgres-extension
Laravel的扩展PostgreSQL驱动。
v3.1.0
2024-09-04 09:28 UTC
Requires
- php: ^8.1
- ext-json: *
- illuminate/database: ^8.67 || ^9.0 || ^10.0 || ^11.0
- sunaoka/laravel-postgres-range: ^2.0.0
Requires (Dev)
- larastan/larastan: ^1.0 || ^2.0
- laravel/pint: ^1.17.3
- orchestra/testbench: ^6.19 || ^7.0 || ^8.0 || ^9.0
- phpstan/phpstan-mockery: ^1.1
README
安装
composer require sunaoka/laravel-postgres-extension
配置
php artisan vendor:publish --tag=postgres-extension
功能
-
RETURNING
- 更新
- 删除
-
缓存"information_schema"表。
-
范围类型
使用方法
表
CREATE TABLE some_models ( id bigserial PRIMARY KEY NOT NULL, code text NOT NULL, term tsrange NOT NULL, CONSTRAINT code_uq UNIQUE (code) );
模型
<?php namespace App\Models; class SomeModel extends \Sunaoka\LaravelPostgres\Eloquent\Model { protected $casts = [ 'term' => \Sunaoka\LaravelPostgres\Eloquent\Casts\TsRangeCast::class, // tsrange ]; }
RETURNING
$some = SomeModel::whereId(1) ->returning(['*']) ->update([ 'term' => new TsRange('2020-09-01 00:00:00', '2020-09-01 23:59:59'), ]); echo get_class($some); // => Illuminate\Database\Eloquent\Collection echo get_class($some->first()); // => App\Models\SomeModel
update "some_models" set "term" = '[2020-09-01 00:00:00,2020-09-01 23:59:59)' where "id" = '1' returning *
缓存"information_schema"表。
永久缓存如下表的查询结果。
select * from information_schema.tables where table_schema = 'public' and table_name = 'some_models'