百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

flywheel

> 编程语言
开源

这是一个面向 PHP 的无服务器的扁平文件数据库,可以以 JSON、YAML 或 Markdown 格式存储数据。

333 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

这是一个面向 PHP 的无服务器的扁平文件数据库,可以以 JSON、YAML 或 Markdown 格式存储数据。

Flywheel

A flat-file, serverless, document database for PHP that can store data in JSON, YAML or Markdown formats.

Often MySQL can be overkill for a small site or blog installation. Although it's present by as standard on many hosting packages it still requires several manual steps including configuration, user and databases creation etc.

Additionally, content stored in MySQL databases is impossible (or at least very difficult) to track using version control software. This makes sharing a site or app between a team difficult, requiring everybody to have access to a master database or their own copy. There's also complications when apps are setup on staging servers and changes that users make must be reflected in a developer's local copy. You've probably come up against this issue in the past and it's all a bit of a mess.

Flywheel hopes to enable a new breed of PHP apps and libraries by giving developers access to a datastore that acts in a similar way to a NoSQL database but has zero external dependencies. Documents (essentially associative arrays), can be saved and retrieved, sorted and limited.

Currently Flywheel is in heavy development and is not production ready yet. You might find that documents created from one version of Flywheel can't be loaded by another right now. As we get closer and closer to a v1 this is less likely to happen.

Flywheel is opinionated software. The following is assumed:

  • Simple data structures are best.
  • You're not going to be storing tens of thousands of documents.

Requirements

  • PHP 5.3+
  • Composer

Optionally

  • APC / APCu - caches documents and queries in memory for huge performance gains.

Installation

Use Composer to install the flywheel package. Package details can be found on Packagist.org.

Run composer require jamesmoss/flywheel in your project directory to install the Flywheel package.

Use

…

Querying

You can filter down the number of documents returned by using the where, andWhere and orWhere methods on a query.

…

You can pass in an anonymous function to the where, andWhere and orWhere methods to group predicates together. The anonymous function takes one parameter which is an instance of JamesMoss\Flywheel\Predicate and has the same methods. You can nest as many times you as like.

php
$posts = $repo->query()
    ->where('wordCount', '>', 100)
    ->andWhere(function($query) {
    	$query->where('author', '==', 'Hugo')
    	$query->orWhere('dateAdded', '>', new \DateTime('2014-05-04'))
    })
    ->execute();

Important Traditional logical operator precedence is not implemented yet. If you have a mix of AND and ORs then you might not see the behaviour you expect. Currently AND predicates are processed before OR, regardless of the order they were defined in. Always use anonymous function to group your predicates together explictly if you have a mix of AND and ORs.

The list of available comparison operators are:

  • == Equality
  • === Strict equality
  • != Not equals
  • !== Strict not equals
  • > Greater than
  • >= Greater than or equal to
  • `query() ->orderBy('wordCount ASC') ->execute();

// You can use sub keys too $posts = $repo->query() ->orderBy('translations.de DESC') ->execute();

// It's possible to sort on multiple fields by passing in an array to orderBy $posts = $repo->query() ->orderBy(['name ASC', 'age DESC']) ->execute();

// Use the special __id field name to sort by the document's ID $posts = $repo->query() ->orderBy('__id') ->execute();


You can limit how many documents get returned from the repo using `limit`. Offsets
are also supported much like a traditional database.

```php
// Get the last 5 blog posts
$posts = $repo->query()
	->where('published', '==', 'true')
    ->orderBy('dateAdded DESC')
    ->limit(5)
    ->execute();

 // Get 25 blog posts offset by 100 from the start.
 $posts = $repo->query()
 	->where('published', '==', 'true')
    ->orderBy('dateAdded DESC')
    ->limit(25, 100)
    ->execute();

…

php
$config = new Config('/path/to/writable/directory', array(
    'formatter' => new \JamesMoss\Flywheel\Formatter\YAML,
))

The following formatter classes are available.

  • JamesMoss\Flywheel\Formatter\JSON - Will attempt to pretty print output if using PHP 5.4+. File extension is json.
  • JamesMoss\Flywheel\Formatter\YAML - Uses yaml file extension, not yml.
  • JamesMoss\Flywheel\Formatter\Markdown - Takes an optional parameter in the constructor which dictates the name of the main field in the resulting Document (Defaults to body). File extension is md. Markdown isn't converted into HTML, that's up to you.

Important If you use the YAML or Markdown formatters when using the --no-dev flag in Composer you'll need to manually add mustangostang\spyc to your composer.json. Flywheel tries to keep it's dependencies to a minimum.

If you write your own formatter it must implement JamesMoss\Flywheel\Formatter\Format.

Todo

  • More caching around Repository::findAll.
  • Indexing.
  • HHVM support.
  • Abstract the filesystem, something like Gaufrette or Symfony's Filesystem component?
  • Events system.
  • Option to rehydrate dates as datetime objects?
  • More serialisation formats? PHP serialized, PHP raw?
  • More mocks in unit tests.
  • Simple one-to-one and many-to-one joins.
  • Implement proper logical operator precedence in queries
  • Add ability to register own comparison operators

Running tests

There is good test coverage at the moment. If you'd like to run the tests yourself, use the following:

$ composer install
$ phpunit

Contributing

If you spot something I've missed, fork this repo, create a new branch and submit a pull request. Make sure any features you add are covered by unit tests and you don't break any other tests.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言