承接 hyvr/ray-db 相关项目开发

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

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

hyvr/ray-db

Composer 安装命令:

composer require hyvr/ray-db

包简介

README 文档

README

Fishline logo RayDB is a lightweight NoSQL database built in PHP that relies solely on plain JSON files, with no third-party dependencies. Its simple file-based design makes it ideal for static websites or projects that need an easy, manageable way to store content. It’s intended for handling a few gigabytes of data under low to medium workloads, making it suitable for low-traffic environments where a full traditional database would be unnecessary.

⚡ Get started

RayDB can be installed from the composer package manager. Make sure you installed PHP and Composer from the requirments section before continuing. Run the below command to install the RayDB.

composer require hyvr/ray-db

Example usage is given below. More usage examples are details given in the below section.

<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  $ray = new Ray(__DIR__.'/buckets');

  $bucket = $ray->bucket('fruits');

  $bucket->insert([
    'name' => 'apple',
    'color' => 'red',
    'size' => ['small', 'medium'],
    'orgin' => [
      'name' => 'India',
      'code' => 'IN'
    ]
  ]);

  $fruits = $bucket->query()->sortBy('name')->get();
?>

📂 Concept

RayDB saves all the data in JSOn files. These can be created or edited manually. All database have a folder where these JSON files will be saved. Here is the core concept of RayDB explained below.

  • Buckets are like folders inside the database where similar JSON documents are saved.
  • Document is a JSON file where the actual data is saved. Each document will have an unique _id. _id of the document and the file name should be same. You can give an _id during insert, if not that system will give a random unique string.

🎩 Requirments

The RayDB has a few system requirements. You should ensure that your local system has the following minimum PHP version and extensions:

  • PHP >= 8.0.0
  • Composer >= 1.0.0

🚀 Usage

Examples on how to use RayDB is given in grouped sections below.

Initializing
<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  // Initializing database 
  $ray = new Ray(__DIR__.'/buckets');

  // Initializing database with config 
  $ray = new Ray(__DIR__.'/buckets', [
    'folder_permission' => 0777,
    'pretty' => true
  ]);

  // Initializing database also create the database folder
  $ray = new Ray(__DIR__.'/buckets', [], true);
?>
Insert
<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  $ray = new Ray(__DIR__.'/buckets');

  // Create a bucket called 'fruits' and insert a document
  $bucket = $ray->bucket('fruits');

  $bucket->insert([
    'name' => 'apple',
    'color' => 'red',
    'size' => ['small', 'medium'],
    'orgin' => [
      'name' => 'India',
      'code' => 'IN'
    ]
  ]);

  // Insert a document with id
  $bucket->insert([
    '_id' => 'apple',
    'name' => 'apple',
    'color' => 'red'
  ]);

  // Bulk insert
  $bucket->insert([
    [
      'name' => 'apple',
      'color' => 'red'
    ],[
      'name' => 'orange',
      'color' => 'orange'
    ]
  ]);

  // Another method to insert with object
  $apple = $ray->bucket('fruits')->new('apple');
  $apple->name = 'apple';
  $apple->color = 'red';
  $apple->save();
?>
Query
<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  $ray = new Ray(__DIR__.'/buckets');

  $bucket = $ray->bucket('fruits');

  // Get a document with id
  $apple = $bucket->find('apple');

  echo $apple->name;
  echo $apple->color;

  // Query all the documents in the bucket
  $fruits = $bucket->query()->get();

  foreach($fruits as $fruit){
    echo $fruit->name;
    echo $fruit->color;
  }

  // Query using condition
  $fruits = $bucket->query()->where('color', 'red')->get();
  
  $fruits = $bucket->query()->where('size', '>=', 100)->get();

  foreach($fruits as $fruit){
    echo $fruit->name;
    echo $fruit->color;
  }

  // Query using condition and get first
  $fruit = $bucket->query()->where('color', 'red')->first();

  echo $fruit->name;
  echo $fruit->color;
?>
Update
<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  $ray = new Ray(__DIR__.'/buckets');

  $bucket = $ray->bucket('fruits');

  // Find a document with id and update it
  $apple = $ray->bucket('fruits')->find('apple');
  $apple->color = 'red';
  $apple->save();

  // Bulk update with id
  $bucket->update([
    [
      '_id' => 'apple',
      'name' => 'apple',
      'color' => 'red'
    ],[
      '_id' => 'orange',
      'name' => 'orange',
      'color' => 'orange'
    ]
  ]);
?>
Upsert
<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  $ray = new Ray(__DIR__.'/buckets');

  $bucket = $ray->bucket('fruits');

  // Upsert using id
  $apple = $ray->bucket('fruits')->newOrUpdate('apple');
  $apple->color = 'red';
  $apple->save();

  // Bulk upsert with id
  $bucket->updateOrInsert([
    [
      '_id' => 'apple',
      'name' => 'apple',
      'color' => 'red'
    ],[
      '_id' => 'orange',
      'name' => 'orange',
      'color' => 'orange'
    ]
  ]);
?>
Sort
<?php
  require 'vendor/autoload.php';

  use Hyvr\RayDB\Ray;

  $ray = new Ray(__DIR__.'/buckets');

  $bucket = $ray->bucket('fruits');

  // Sort by ascending
  $fruits = $bucket->query()->sort('color')->get();

  // Sort by descending
  $fruits = $bucket->query()->sort('color', 'desc')->get();

  // Sort by ascending with condition
  $fruits = $bucket->query()->where('color', 'red')->sort('color')->get();
?>

📃 License

RayDB is licensed under the MIT License.

hyvr/ray-db 适用场景与选型建议

hyvr/ray-db 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 hyvr/ray-db 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-07