定制 vuthaihoc/crdb-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

vuthaihoc/crdb-laravel

最新稳定版本:v1.3.6

Composer 安装命令:

composer require vuthaihoc/crdb-laravel

包简介

This is my package cockroachdb-laravel

README 文档

README

Latest Version on Packagist PHPUnit Tests Check & fix styling Total Downloads codecov Help Fund License PHP Version Require

A driver/grammar for Laravel that works with CockroachDB. While CockroachDB is compatible with Postgresql, this support is not 1 to 1 meaning you may run into issues, this driver hopes to resolve those problems as much as possible.

Laravel 9 through to Laravel 10 is supported and tested against CockroachDB 22 & 23.

Supporting Open Source

Peter Fox here, I just want to say this project has been my hardest yet. It's been a real labour of love to make and takes up a lot of time trying to organise the test suite so that compatibility is maintained between Eloquent and CockroachDB.

I see a lot of promise in using CockroachDB's serverless offering which is what compelled me to go down this route originally. You can read an article I made about using their service.

If you're using this project at all then do please consider sponsoring me as a way of encouraging more development.

Installation

You can install the package via composer:

composer require ylsideas/cockroachdb-laravel

You need to add the connection type to the database config:

'crdb' => [
    'driver' => 'crdb',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '26257'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
    'schema' => 'public',
    'sslmode' => 'prefer',
]

You can also use URLs.

DATABASE_URL=cockroachdb://<username>:<password>@<host>:<port>/<database>?sslmode=verify-full

Usage

To enable set DB_CONNECTION=crdb in your .env.

  • Using storing (when create an index or unique index)

    $table->string('email'); $table->unique('email')->storing('password');

Notes

CockroachDB should work inline with the feature set of Postgresql, with some exceptions. You can look at the features of each CockroachDB server in the CockroachDB Docs.

Deletes with Joins

CockroachDB does not support performing deletes using joins. If you wish to do something like this you will need to use a sub-query instead.

At current if you try to call the delete method of the Query builder together with a join then a YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException exception will be thrown.

Fulltext Search

Eloquent and Postgresql support Fulltext search. CockroachDB does not support any full text search meaning the feature cannot be used when using this driver.

At current if you try to create a Fulltext index using the Schema builder or try to use the whereFulltext method of the Query builder a YlsIdeas\CockroachDb\Exceptions\FeatureNotSupportedException exception will be thrown.

Serverless Support

Cockroach Serverless requires you to provide a cluster with connection. Laravel doesn't provide this out of the box, so, it's being implemented as an extra cluster parameter in the database config. Just pass the cluster identification from CockroachDB Serverless.

Schema Dumps

You may use schema dumps. I'm not 100% sure the functionality is correct in line with other drivers. Please raise an issue if it isn't working as expect for you.

'crdb' => [
    'driver' => 'crdb',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '26257'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
    'schema' => 'public',
    'sslmode' => 'prefer',
    'cluster' => env('COCKROACHDB_CLUSTER', ''),
]

You may also use a URL in the following format.

DATABASE_URL=cockroachdb://<username>:<password>@<host>:<port>/<database>?sslmode=verify-full&cluster=<cluster>

Testing

The tests try to closely follow the same functionality of the grammar provided by Laravel by lifting the tests straight from laravel/framework. This does provide some complications. Namely, cockroachdb is designed to be distributed so primary keys do not occur in sequence.

Tests should also try to be compatible with not just the latest version of Laravel but across Laravel 8, 9 and 10, this requires some tests to be skipped.

You can run up a local cockroachDB test instance using Docker compose.

docker-composer up -d

If you need to you may run the docker compose file with different cockroachdb versions

VERSION=v23.1.13 docker-compose up -d

Then run the following PHP script to create a test database and user

php ./database.php

Afterwards you can run the test suite.

composer test

To clean up, you only need stop docker composer.

docker-composer down

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

vuthaihoc/crdb-laravel 适用场景与选型建议

vuthaihoc/crdb-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 786 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 vuthaihoc/crdb-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-24