PHPackages                             p3k/quartz-db - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. p3k/quartz-db

ActiveLibrary[Database &amp; ORM](/categories/database)

p3k/quartz-db
=============

A flat-file database optimized to hold time-series data.

0.2.0(4y ago)215123[3 issues](https://github.com/aaronpk/QuartzDB/issues)[1 PRs](https://github.com/aaronpk/QuartzDB/pulls)Apache-2.0PHPCI passing

Since Sep 21Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/aaronpk/QuartzDB)[ Packagist](https://packagist.org/packages/p3k/quartz-db)[ RSS](/packages/p3k-quartz-db/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (1)Versions (11)Used By (0)

QuartzDB
========

[](#quartzdb)

A flat-file database optimized to hold time-series data.

When should I use this?
-----------------------

[](#when-should-i-use-this)

Some great uses for QuartzDB:

- Storing GPS logs (just store your records as GeoJSON!)
- Storing chat logs from IRC, Slack, SMS or iMessage, etc
- Storing sensor logs from IoT devices, such as in-house environment sensors

You should use this if...

- ... you believe text files are easier to back up and keep multiple copies of
- ... you believe text files are more likely than binary database files to last long-term

API
---

[](#api)

```
$db = new Quartz\DB('/path/to/folder', 'w');
$db = new Quartz\DB('/path/to/folder', 'r');
```

### Adding Records

[](#adding-records)

```
$db->add($date, $data);
```

This will add the entry always to the end of the appropriate file, since it is expected that data will be inserted in order. If you need to insert out of order, you can run the maintenance task to re-sort the date's file when needed.

### Querying

[](#querying)

Range

```
$results = $db->queryRange($fromDate, $toDate);
// Loop through the result set.
// The JSON is parsed when the row is accessed.
foreach($results as $id=>$record) {
  echo $id . ": " . $record->property . "\n";
}
```

Last n records

```
$results = $db->queryLast(10);
foreach($results as $id=>$record) {
  echo $id . ": " . $record->property . "\n";
}
```

Single Record

```
$db->getByDate($date);
$db->getByID("YYYYMMDDline");
```

### Maintenance

[](#maintenance)

```
// Re-sorts all the data in the shard by date.
// This requires loading the entire file into memory.
$shard = $db->getShard("YYYY","MM","DD");
$shard->sort();
```

Filesystem
----------

[](#filesystem)

One file per day.

The base path of the database contains a "data" folder and "index" folder.

```
/data/
     /2015/08/05.txt
     /2015/08/05.meta
     /2015/08/06.txt
     /2015/08/06.meta
     /2015/08/07.txt
     /2015/08/07.meta

```

Files contain one record per line, separated by newlines. The first 26 characters are the date with microsecond precision, followed by a space, followed by the JSON record.

```
2015-08-03 09:00:00.000000 {"foo":"bar","value":300}
2015-08-03 09:00:01.000000 {"foo":"bar","value":300}
2015-08-03 09:00:02.000000 {"foo":"bar","value":300}

```

The ".meta" files are for storing information about the data file. Currently the only thing in the meta file is line 1 contains the number of lines in the data file.

There is also a file in the root of the data folder containing the date of the last date seen. This is for quickly retrieving the last n records in the database without having to search the filesystem for all files.

License
-------

[](#license)

Copyright 2015-2017 by Aaron Parecki

QuartzDB is licensed under the [Apache 2.0 license](http://opensource.org/licenses/Apache-2.0)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance54

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~321 days

Recently: every ~362 days

Total

8

Last Release

1690d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/385b302aef27e9e72ddfbf65c8b15cfce5946744fe2e541c5b415665fc2351fc?d=identicon)[aaronpk](/maintainers/aaronpk)

---

Top Contributors

[![aaronpk](https://avatars.githubusercontent.com/u/113001?v=4)](https://github.com/aaronpk "aaronpk (28 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/p3k-quartz-db/health.svg)

```
[![Health](https://phpackages.com/badges/p3k-quartz-db/health.svg)](https://phpackages.com/packages/p3k-quartz-db)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
