承接 martimarkov/postgresify 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

martimarkov/postgresify

Composer 安装命令:

composer require martimarkov/postgresify

包简介

Extended PostgreSQL Functionality for Laravel

README 文档

README

Postgresify

Note

This package is under development.

Table of Contents

What is this?

Installation

Geometric Types

Monetary Types

Network Address Types

Range Types

License

References

What is this?

Postgresify is a package for Laravel and Lumen that extends support to some of the more useful PostgreSQL data types. This package allows you to leverage PostgreSQL's data types, such as point, inet, circle, etc., within Laravel's Schema Builder and retrieve meaningful data from Fluent/Eloquent.

Example Migration:

Schema::create('hotel_search', function (Blueprint $table) {
    // ...

    $table->point('geocode_coordinates');
    $table->ipAddress('visitor_ip_address');
    $table->circle('search_area');
    $table->dateRange('reservation_period');
    $table->money('budget');

    // ...
});

Life's easier, right? The above use cases of PostgreSQL's types eliminate a few immediately noticeable headaches:

  • Point types store geographic coordinates in one field--not two.
  • IP address types will store IPv4 or IPv6--no VARCHAR here.
  • Circle types store a center point and a radius <(x, y), r> in one field. There are 'hackier' ways to store radii related to a center point without this.
  • Date range types store just that, date ranges. This, like the point type, eliminates the necessity of the second field.
  • Money types store a signed, locale-sensitive currency amount, with a range of +/- 92 quadrillion! No more DECIMAL(11,2) or whatever people do these days.

Now let's discuss the actual utility afforded by these additional types. PostgreSQL is nicely equipped with functions and operators for meaningfully working with these data types. This depends on the architecture of your environment, but these types combined with the functions/operators allow you to offload some work onto your database server--which might be faster and could reduce some responsibilities within your application's code. Your mileage may vary. See this StackExchange Q/A.

Installation

To install this package you will need:

  • Laravel 5.1+ or Lumen 5.1+
  • PHP 5.5.9+

This package is intended for PostgreSQL 9.4+.

Add this package to your `composer.json` file as a dependency:


### Laravel

After installing via Composer, register Postgresify's ```DatabaseServiceProvider``` in your ```config/app.php```
configuration file like so:
```php
'providers' => [
    // Other service providers...

    Aejnsn\Postgresify\DatabaseServiceProvider::class,
],
```

### Basic Usage
If you would like code completion in your IDE for the PostgreSQL types made available via Postgresify, be sure your migrations (or other uses of Illuminate's Schema Builder) ```use``` the ```Aejnsn\Postgresify\Database\Schema\Blueprint``` class as in this example:
```php
<?php

use Aejnsn\Postgresify\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateHotelsTable extends Migration
{
    public function up()
    {
        Schema::create('hotels', function (Blueprint $table) {
            $table->dateRange('reservation');

            // Build your schema using PostgreSQL's awesome types...
        });
    }

    // ...
}
```

## Geometric Types

The geometric types in PostgreSQL can give you a ton of power while reducing complexity in your application.
> PostgreSQL's geometric types do not try to replace the need for [PostGIS](http://postgis.net/) in cases where
> geographic calculations are performed. Remember this is geometric, not geographic--the Earth is not flat, or even a
> perfect sphere, it's an oblate spheroid (ellipsoid). That being said, don't use geometric types for heavy geographic
> work. Please use PostGIS if you determine a need, your accuracy depends on it. For those of you would-be geodesy
> aficionados, check out Charles F. F. Karney's work. Karney's algorithms are accurate to within 15 nm.



### Box

### Circle

### Line

### Line Segment

### Path

### Point

### Polygon


## Monetary Types

Methods of storing currency in an application/database make a hot topic for debate, and there is a ton of misinformation
on this topic. People start citing [GAAP](http://www.fasab.gov/accounting-standards/authoritative-source-of-gaap/), and
then it boils down to developers' non-standard preferences. There is too much uncertainty, and I just do not like it.
Let's look at some common methods for storing currency:

1. **Store as ```float```**. Don't do this, you'll have garbage for accuracy.
2. **Store as ```decimal```/```numeric```**. This is fine and handles the cases where you need to store fractions of a
cent. Decimal can be a hit to your performance in analytical operations.
3. **Store as ```integer``` using cents (or other currency's base unit) or use ```money```**. This is best, and works in
cases where you do **not** need fractions of a cent. PostgreSQL's ```money``` stores as an integer (of cents) but cleans
up the display and return of doing so. ```Money``` is more performant than ```decimal```. The range of ```money``` is
-92233720368547758.08 to +92233720368547758.07, so yeah, it will handle large amounts.

### Money


## Network Address Types

Network addresses can be a pain to work with. Imagine the use case where you would need to query all IP addresses of a
certain subnet mask. PostgreSQL has [Network Address Functions and Operators](http://www.postgresql.org/docs/9.4/static/functions-net.html)
for purposes like this.

> I made a [pull request](https://github.com/laravel/framework/pull/12884) for the IP and MAC address types in Laravel. So these two types will be in your initial Laravel installation (5.2.27+), and should work across all of Laravel's supported database systems. However, PostgreSQL, unlike other database systems, has its rich set of network address functions and operators built-in.

### IP Address

### MAC Address

### Netmask


## Range Types

Ranges are quite powerful. A range includes a lower-bound and an upper-bound, either of which can be inclusive or
exclusive. It would take four columns to build that functionality without a range type. Check out [PostgreSQL's Range
Functions and Operators documentation](http://www.postgresql.org/docs/9.4/static/functions-range.html).

### Date Range

### Integer Range

### Numeric Range

### Timestamp Range

### Timestamp Range w/ Timezone


## License

- This package is licensed under the [MIT license](https://raw.githubusercontent.com/aejnsn/postgresify/master/LICENSE).

## References

- [PostgreSQL 9.4 Manual](http://www.postgresql.org/docs/9.4/static/datatype.html)

martimarkov/postgresify 适用场景与选型建议

martimarkov/postgresify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.07k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「postgresql」 「pgsql」 「laravel」 「types」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 martimarkov/postgresify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 martimarkov/postgresify 我们能提供哪些服务?
定制开发 / 二次开发

基于 martimarkov/postgresify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-20