承接 james-draper/sqlite-key-value-store 相关项目开发

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

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

james-draper/sqlite-key-value-store

Composer 安装命令:

composer require james-draper/sqlite-key-value-store

包简介

README 文档

README

A package for creating self-contained sqlite key-value stores held in a file.

Usage

A key-value file is managed via the \SqliteKeyValueStore\Store class. To create an instance, pass the absolute path to the key-value file into the constructor. If the file does not exist yet, the constructor will create it.

$store = \SqliteKeyValueStore\Store('/path/to/file');

There are 2 exceptions that can be thrown by the constructor:

  • \LogicException if the path is :memory:. In memory databases are strictly forbidden.
  • \SqliteKeyValueStore\Exception if the database connection could not be established.

Getting a value from the store

Values can be retrieved from the store via the get method:

$value = $store->get('key', 'default value');

If the key exists then it is returned. If it does not then the default value (second parameter) is returned instead. The default value is null if not specified. \SqliteKeyValueStore\Exception if there was an issue retrieving the key.

Setting a value to the store

Values can be added/updated to the store via the set method:

$value = $store->set('key', 'value');

If the key exists then it is updated. If it does not then it is created. \SqliteKeyValueStore\Exception if there was an issue setting the key. This method returns the instance for method chaining.

Removing a value from the store

Values can be removed from the store via the remove method:

$value = $store->remove('key');

If the key exists, then it is removed. If it does not exist then nothing happens. \SqliteKeyValueStore\Exception if there was an issue deleting the key. This method returns the instance for method chaining.

Searching the store

There are 3 ways to search the store:

// search by keys containing the substring "some_key" where "?" is a wildcard.
$matches = $store->searchKeys('?some_key?', '?');

// search by values containing the substring "some_value" where "?" is a wildcard.
$matches = $store->searchValues('?some_value?', '?');

// search by keys containing the substring "some_key"
// AND by values containing the substring "some_value"
// where "?" is a wildcard.
$matches = $store->search('?some_key?', '?some_value?', '?');

The wildcard is an optional argument that defaults to *. If it is not exactly 1 character then \SqliteKeyValueStore\Exception is thrown. Each method returns a key-value array of pairs that were matched in the store.

Backing up the store

The store can be backed up by calling backup and specifying a path to backup the database to. The path must be empty or \SqliteKeyValueStore\Exception is thrown. While backing up the database is locked, and all write operations will block until the backup is complete.

$store->backup('backup/path');

Getting the store size

The size of the store can be determined by calling getSize which returns the number of key-value pairs in the store as an integer.

$store->getSize();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固