Home > PHP Framework > Laravel > How Laravel 7 supports PosgreSQL range types

How Laravel 7 supports PosgreSQL range types

Guanhui
Release: 2020-07-20 12:41:28
forward
2595 people have browsed it

How Laravel 7 supports PosgreSQL range types

The PosgreSQL range type package written by @belamov provides range type support for the Postgres database:

Schema::create('table', function (Blueprint $table) {
    $table->id();
    // ...
    $table->dateRange('date_range');
    $table->timestampRange('timestamp_range');
    $table->floatRange('float_range');
    // 对于 int4range
    $table->integerRange('integer_range');
    // 对于 int8range
    $table->bigIntegerRange('integer_range');

    // 您可以添加任何修改
    // $table->dateRange('date_range')->nullable();
    // $table->dateRange('date_range')->default('[2010-01-01,2010-01-02)');
});
Copy after login

The main features of this package include:

  • Extends Laravel's PostgresGrammar and PostgresConnection classes to provide a fluent API for range columns.

  • The following Postgres range types are supported: daterange, tsrange, numrange, intrange and timerange.

  • Many convenient query building macros (i.e. whereRangeContains($left,$right)

  • Model attribute conversion

The model attribute conversion provided by this package provides convenience for using ranges on model instances. For example:

use Belamov\PostgresRange\Ranges\IntegerRange;

$range = new IntegerRange(10, 20, '[', ')');

$range->from(); // 10
$range->to(); // 20
(string) $range; // [10,20)
$range->forSql(); // '[10,20)'
Copy after login

You can learn about it at belamov/postgres-range More information about this package, complete installation instructions, and view the source code on GitHub. This package has an excellent blog post that will give you a quick introduction to the powerful features available in Postgres range types: Using PostgreSQL Ranges in Laravel 7 .

Recommended tutorial: "Laravel Tutorial"

The above is the detailed content of How Laravel 7 supports PosgreSQL range types. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template