承接 almacil/php-database 相关项目开发

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

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

almacil/php-database

最新稳定版本:1.0.1

Composer 安装命令:

composer require almacil/php-database

包简介

A simple flat file database designed to persist data using just PHP and flat files. Perfect solution when no other database is available or for small projects.

README 文档

README

GitHub last commit GitHub tag (latest by date) Packagist PHP Version Support GitHub

🗃 Almacil PHP Database

This is a simple flat file NoSQL like database implemented in PHP for small projects without any third-party dependencies that store data in plain JSON files.


Do you want to contribute?
Donate 1€

Features

  • Lightweight and Secure
  • Easy to get started
  • No external dependencies
  • CRUD (create, read, update, delete) operations
  • Supports multiple databases and tables/collections

Installation

Installation is possible using Composer

composer requiere almacil/php-database

Usage

Summary

// Create instance
$db = new \Almacil\Database($database);

// Basic
$db->find($collection, /* function to find */);
$db->insert($collection, $item);
$db->update($collection, /* function to find */, $update);
$db->remove($collection, /* function to find */, $permanent);

// More
$db->count($collection, /* function to find */);
$db->findOne($collection, /* function to find */);
$db->upsert($collection, /* function to find */, $update);
$db->drop($collection);
$db->newid();

Create instance

Create an instance of \Almacil\Database. Optionally, we can maintain the order of the databases and collections with a hierarchy using slash. We can also decide that the directory corresponds to a database and create another instance for another database in another directory.

// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';

// Directory containing the json files of databases
$database = __DIR__ . '/data';

// Create de instance
$db = new \Almacil\Database($database);

// "database/collection" or "collection" or "collection/subcollection"
$collection = 'mycollection/mysubcollection';

Find

// ... after insert

$find = new stdClass();
$find->_id = $newItem->_id;

$items = $db->update($collection, function($item) use ($find) {
    return $find->_id === $item->_id;
});

Insert

// ... after create instance $db
$item = new stdClass();
$item->name = 'Rubén';
$newItem = $db->insert($collection, $item);

Update

// ... after insert

$find = new stdClass();
$find->_id = $newItem->_id;

$update = new stdClass();
$update->name = 'Rubén Pérez';

$numberItemsUpdated = $db->update($collection, function($item) use ($find) {
    return $find->_id === $item->_id;
}, $update);

Remove

When we delete an element, we don't really delete it but we set the _removed_at field with the value of microtime(). If we want to delete the element permanently we will send true in the third argument.

// ... after insert

$find = new stdClass();
$find->_id = $newItem->_id;

$permanent = true;

$numberItemsRemoved = $db->remove($collection, function($item) use ($find) {
    return $find->_id === $item->_id;
}, $permanent);

Do you want to contribute?
Donate 1€

Made with ❤️ by developer for developers

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-06