urameshibr/pg-interval-support

支持 PostgreSQL 数据库中的区间字段类型。

1.0 2019-01-11 10:48 UTC

This package is auto-updated.

Last update: 2024-09-12 05:39:16 UTC


README

支持 PostgreSQL 数据库中的区间字段类型。

如何安装

composer require urameshibr/pg-interval-support
  • 在 config/app.php 中添加服务提供者
'providers' => [
    // Other providers

    Urameshibr\PgIntervalSupport\Providers\PostgresTypeGrammarIntervalServiceProvider::class,
],

用法

  • 如何在迁移文件中添加 "interval" 类型的字段
$table->addColumn('interval', 'field_name')
  • 如何查询该区间字段
// The format: 
DB::table('table_name')->whereInterval('field_name', 'operator', 'interval')

// Example 1
DB::table('tours')->whereInterval('duration', '>=', '02:00:00')->get()

// Example 2
DB::table('tours')->whereInterval('duration', '>=', '2 hours')->get()

// Example 3
YourModel::whereInterval('duration', '>=', '2 hours')->get()
  • 观察:方法 "whereInterval( )" 与查询构建器对象一起工作

享受!