hyvr/ray-db
Composer 安装命令:
composer require hyvr/ray-db
包简介
README 文档
README
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.
Bucketsare like folders inside the database where similar JSON documents are saved.Documentis a JSON file where the actual data is saved. Each document will have an unique_id._idof the document and the file name should be same. You can give an_idduring 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-07