定制 robert-grubb/filerdb-php 二次开发

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

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

robert-grubb/filerdb-php

Composer 安装命令:

composer require robert-grubb/filerdb-php

包简介

FilerDB PHP Package

README 文档

README

A simplistic PHP flat file database designed to get your application up and running fast. Please note this package is currently in development and is not yet at a release.

Usage

Install via composer:

composer require robert-grubb/filerdb-php

NOTE: Please make sure your database directory has correct permissions for READ and WRITE.

Instantiating

use FilerDB\Instance;

// Instantiate Database
$filerdb = new Instance([ 'root' => __DIR__ . '/database/' ]);

Configuration

[

  /**
   * This is the root path for FilerDB.
   */
  'root' => false,

  /**
   * If the root path does not exist, try
   * and create it.
   */
  'createRootIfNotExist' => false,

  /**
   * If the database does not exist, try
   * and create it.
   */
  'createDatabaseIfNotExist' => false,

  /**
   * If the collection does not exist, attempt
   * to create it.
   */
  'createCollectionIfNotExist' => false,

  /**
   * If the insert and update logic handles
   * the createdAt and updatedAt timestamps
   * automatically
   */
  'includeTimestamps' => false

]

Creating a database

$filerdb->databases->create('dev');

Check if database exists

$filerdb->databases->exists('dev'); // Returns true or false

List all databases

$filerdb->databases->list(); // Returns array

Deleting a database

$filerdb->databases->delete('dev');

Selecting a default database

Selecting a default database allows you to not have to specify the database on every call. Please refer to the below code on how to do that.

// Specify it in the configuration:
$filerdb = new Instance([
  'path' => __DIR__ . '/database/',
  'database' => 'database_name'
]);

or

$filerdb->selectDatabase('database_name');

With the above, you can now do the following:

$filerdb->collection('users')->all(); // Notice no ->database()

List collections in a database

$filerdb->database('dev')->collections(); // Returns array

Check if collection exists

$filerdb->database('dev')->collectionExists('dev'); // Returns true of false

Creating a collection

$filerdb->database('dev')->createCollection('users');

Deleting a collection

$filerdb->database('dev')->deleteCollection('users');

Empty a collection

$filerdb->database('dev')->collection('users')->empty();

Inserting a document

$filerdb->database('dev')->collection('users')->insert([
  'username' => 'test',
  'email'    => 'test@test.com'
]);

Updating a document


// By a specific document
$filerdb
  ->database('dev')
  ->collection('users')
  ->id('ad23tasdg')
  ->update([
    'username' => 'test2'
  ]);

// Where all usernames equal test
$filerdb
  ->database('dev')
  ->collection('users')
  ->filter(['username' => 'test'])
  ->update([
    'username' => 'test2'
  ]);

Deleting a document

// Specific document
$filerdb
  ->database('dev')
  ->collection('users')
  ->id('asdfwegd')
  ->delete();

// With filters
$filerdb
  ->database('dev')
  ->collection('users')
  ->filter(['username' => 'test'])
  ->delete();

Retrieving all documents

$filerdb->database('dev')->collection('users')->all()

Retrieving document by id

$filerdb
  ->database('dev')
  ->collection('users')
  ->id('asdf23g')
  ->get();

Retrieving document by filters

// Get users with username of test and greater than age of 10.
$filerdb
  ->database('dev')
  ->collection('users')
  ->filter(['username' => 'test'])
  ->filter([ ['age', '>', '10'] ])
  ->get();

Specify fields that come back in response

// Only returns the username field
$filerdb
  ->database('dev')
  ->collection('users')
  ->get(['username']);

Ordering documents by a field

// Get users with username of test and greater than age of 10.
$filerdb
  ->database('dev')
  ->collection('users')
  ->orderBy('username', 'asc')
  ->get();

Limiting number of documents

// Pull upto 10 documents
$filerdb
  ->database('dev')
  ->collection('users')
  ->limit(10)
  ->get();

Offsetting documents

// Pull upto 10 documents, but start at the
// 9th array key.
$filerdb
  ->database('dev')
  ->collection('users')
  ->limit(10, 9)
  ->get();

Backups

You can now programmatically backup your database. You can do so by using the following code:

$filerdb->backup->create('file_name_here.zip');

This was provided so you can manually backup your database via your own command line script, or automatically via a cron job, or something similar.

robert-grubb/filerdb-php 适用场景与选型建议

robert-grubb/filerdb-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 79 次下载、GitHub Stars 达 8, 最近一次更新时间为 2020 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 robert-grubb/filerdb-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-30