PHPackages                             devfake/novus - 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. devfake/novus

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

devfake/novus
=============

JSON-File Database For PHP

7132[1 issues](https://github.com/devfake/novus/issues)PHP

Since Sep 3Pushed 10y ago5 watchersCompare

[ Source](https://github.com/devfake/novus)[ Packagist](https://packagist.org/packages/devfake/novus)[ RSS](/packages/devfake-novus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![novus](https://camo.githubusercontent.com/e1779aad443828efaa0eba7f4583a9f8530885b284de10feb29a3da42a73dc58/687474703a2f2f38302e3234302e3133322e3132302f6e6f7675732f6769746875625f6865616465722e706e67)](https://camo.githubusercontent.com/e1779aad443828efaa0eba7f4583a9f8530885b284de10feb29a3da42a73dc58/687474703a2f2f38302e3234302e3133322e3132302f6e6f7675732f6769746875625f6865616465722e706e67)

Novus is a JSON-file database for PHP. Use this package for quick prototyping and to testing your application without to configure a mysql (or other) database.

The syntax is a little like more typical sql, and not like ORM.

**Warning:** This package is incomplete and it miss some important features.

- [Get Started](#get-started)
- [Quick Overview](#quick-overview)
- [First Steps](#first-steps)
- [Options](#options)
- [Argument Values](#argument-values)
- [Create Table](#create-table)
- [Add Fields](#add-fields)
- [Rename Fields](#rename-fields)
- [Remove Fields](#remove-fields)
- [Insert](#insert)
- [Select](#select)
- [Order](#order)
- [Limit](#limit)
- [Where Conditions](#where-conditions)
- [Update](#update)
- [Delete And Remove](#delete-and-remove)
- [Last Primary Key](#last-primary-key)
- [Next Primary Key](#next-primary-key)
- [Rename Primary Key](#rename-primary-key)
- [Last And First](#last-and-first)
- [Find And FindOrFail](#find-and-findorfail)

Get Started
-----------

[](#get-started)

##### Requirements

[](#requirements)

- PHP 5.4+
- Composer

##### Install

[](#install)

The easiest way to install Novus is via [Composer](https://getcomposer.org/). Add this to your `composer.json` file and run `$ composer update`:

```
{
  "require": {
    "devfake/novus": "dev-master"
  }
}
```

Feature release will have a bootstrap file if you don't want to use composer.

Quick Overview
--------------

[](#quick-overview)

Let's see a quick overview of the syntax:

```
$novus = new \Devfake\Novus\Database();

// Create a new 'users' table.
$novus->table('users')->create('username, password, email');

// Add more fields.
$novus->table('users')->addFields('activated');

// Insert data.
$novus->table('users')->insert('username = Arya, email = a.stark@winterfell.com, password = n33dl3, activated = 1');

// Select all data.
$data = $novus->table('users')->select();

// Select only username and email.
$data = $novus->table('users')->select('username, email');

// Select all data from 'users' where id = 1.
$data = $novus->table('users')->where('id = 1')->select();

// Update username.
$novus->table('users')->update('username = Jon');

// Delete all data from 'users'.
$novus->table('users')->delete(true);

// Delete all data from 'users' with soft delete.
$novus->table('users')->delete();

// Remove complete 'users' file.
$novus->table('users')->remove();

// Limit and order data.
$novus->table('users')->where('id > 4')->limit(5)->orderBy('id desc')->select()
```

First Steps
-----------

[](#first-steps)

Once you have created the object, you can normally work with them.

However, there is a little rule: You must always specify which table you're working on at the beginning with `table()`:

```
$novus = new \Devfake\Novus\Database();
$novus->table('myTable')->myMethods();
```

But you can also specify directly a table for the object:

```
$myTable = new \Devfake\Novus\Database('myTable');
$myTable->myMethods();

$users = new \Devfake\Novus\Database('users');
$users->orderBy('username, email')->select('username, email, date');
```

This way is recommended if you are working only with a few tables, or want to make your code a bit more readable. And of course, you have less to write.

Options
-------

[](#options)

You can pass a few options when you instantiate your class.

```
// Pass a single string to specify directly a table.
$novus = new \Devfake\Novus\Database('myTable');

// Or pass a array with conditions.
$novus = new \Devfake\Novus\Database([
  'table' => 'myTable',
  'path' => 'myPathForDatabaseFiles',
  'primaryKey' => 'Number'
]);
```

The `path` for your database files is relative to your root folder (or where your composers `vendor` folder is).

The default folder is `database`. There are a `saves` folder to save your soft deletes.

The `primaryKey` is only needed for the `create()` method.

Argument Values
---------------

[](#argument-values)

```
// First, pass a string as argument and separate the keywords with a comma.
$novus->table('users')->create('username, email, password');

// Or, pass a array as argument.
$novus->table('tableName')->create(['username', 'email', 'password']);
```

What is the difference? The first method is clear and fast to type.

Use the second method if you have commas in your keys. But please, i hope you have no commas (or other special chars) in your field names. The second method you will (or need) to use for insert or update data.

Create Table
------------

[](#create-table)

Let‘s create a users table and work with them over the complete documentation. For the documentation we will work with `table()` to make it a little more detailed.

```
// Create a new file without fields.
$novus->table('users')->create();

// Create a new file with fields.
$novus->table('users')->create('field1, field2');
// Or with the array spelling.
$novus->table('users')->create(['field1', 'field2']);
```

And that‘s it! You need the `create()` method only run once.

There is a new `database/users.json` file. Let‘s open it:

```
{"table":"users","id":1,"fields":[["id"]],"data":[]}

// Format it a bit for the documentation
{
  "table": "users",
  "id": 1,

  "fields": [
    ["id"]
  ],

  "data": []
}
```

So, what we have in our table? First, we have `"table"`, this is our table name, in this case `"users"`. Then comes our primary key, `"id"`. They will automatically increased.

Then we have our `"fields"`. The primary key will added by default.

And last, we have our `"data"`. Since we have no data entered, this field is empty. As you can see, `"fields"` and `"data"` are arrays which contains other arrays.

Add Fields
----------

[](#add-fields)

```
$novus->table('users')->addFields('username, email');
$novus->table('users')->addFields(['username', 'email']);
```

Rename Fields
-------------

[](#rename-fields)

```
$novus->table('users')->renameFields('username = users, email = mail');
$novus->table('users')->renameFields(['username' => 'users', 'email' => 'mail']);
```

Remove Fields
-------------

[](#remove-fields)

The `removeFields()` method also deletes the associated data.

```
$novus->table('users')->removeFields('username, email');
$novus->table('users')->removeFields(['username', 'email']);
```

Insert
------

[](#insert)

```
$novus->table('users')->insert('username = devfake, email = devfakeplus@googlemail.com');
$novus->table('users')->insert(['username' => 'devfake', 'email' => 'devfakeplus@googlemail.com']);
```

Select
------

[](#select)

```
// Select all data from 'users'.
$data = $novus->table('users')->select();
$data = $novus->table('users')->select('*');

// Select only username and email.
$data = $novus->table('users')->select('username, email');
$data = $novus->table('users')->select(['username', 'email']);

// Select all data from where id = 1.
$data = $novus->table('users')->where('id = 1')->select();

// Iterate over $data
foreach($data as $content) {
  echo $content['username'];
}
```

Order
-----

[](#order)

Order your output with the `orderBy()` method.

```
// Order by id ASC and username DESC.
$order = $novus->table('users')->orderBy('id asc, username desc')->select();
// Or with array spelling.
$order = $novus->table('users')->orderBy(['id' => 'asc', 'username' => 'desc'])->select();

// ASC is default passed.
$order = $novus->table('users')->orderBy('id, username desc')->select();
$order = $novus->table('users')->orderBy(['id', 'username' => 'desc')->select();

// ASC and DESC are case insensitive.
$order = $novus->table('users')->orderBy('id DESC, username ASC')->select();
```

Limit
-----

[](#limit)

```
1 => first_user, 2 => second_user, 3 => third_user, 4 => fourth_user, 5 => fifth_user, 6 => sixth_user, 7 => seventh_user
```

These are pseudo data of the users table. With them we demonstrate the `limit()` method.

```
// Select the first three data.
$limit = $novus->table('users')->limit(3)->select();
1 => first_user, 2 => second_user, 3 => third_user

// Select the next four data after the first two.
$limit = $novus->table('users')->limit(2, 4)->select();
3 => third_user, 4 => fourth_user, 5 => fifth_user, 6 => sixth_user

// Select the last three data in reverse.
$limit = $novus->table('users')->limit(3, true)->select();
5 => fifth_user, 6 => sixth_user, 7 => seventh_user

// Select the last four data in reverse before the last two.
$limit = $novus->table('users')->limit(2, 4, true)->select();
2 => second_user, 3 => third_user, 4 => fourth_user, 5 => fifth_user
```

The reverse mode return the data in ASC. Use case is for example a chat.

If you don't want this, order them, for example by id.

```
// Select the last four data without reverse.
$limit = $novus->table('users')->limit(4, true)->orderBy('id DESC')->select();
7 => seventh_user, 6 => sixth_user, 5 => fifth_user, 4 => fourth_user
```

It does not matter whether the `orderBy()` method is written before or after `limit()`.

Where Conditions
----------------

[](#where-conditions)

**Warning:** This method is currently very limited. It only works with `select()` and only one query. But i will fix it soon.

```
$data = $novus->table('users')->where('id = 1')->select();
$data = $novus->table('users')->where('username = Arya')->select();
$data = $novus->table('users')->where('id > 10')->select();
```

Use `=, !=, =, >` and `table('users')->update('username = newUsername, email = newEmail');
$novus->table('users')->update(['username' => 'newUsername', 'email' => 'newEmail']);
```

Delete And Remove
-----------------

[](#delete-and-remove)

If you use `delete()` or `remove()`, novus will make a backup file in the `saves` folder. This folder is created in the beginning and is inside of your database folder.

Pass `true` as argument to avoid the soft delete.

##### Delete

[](#delete)

With `delete()` you can remove a dataset.

**Warning:** This method is currently very limited and removed all data from a table. I will fix it soon with `where()`.

```
$novus->table('users')->delete();
$novus->table('users')->delete(true);
```

##### Remove

[](#remove)

With `remove()` you can remove a complete table file.

```
$novus->table('users')->remove();
$novus->table('users')->remove(true);
```

Last Primary Key
----------------

[](#last-primary-key)

Return the primary key of last data. If data is empty, the method returns `null`.

```
$key = $novus->table('users')->lastPrimaryKey();
```

Next Primary Key
----------------

[](#next-primary-key)

Return the primary key of next insert data.

```
$key = $novus->table('users')->nextPrimaryKey();
```

Rename Primary Key
------------------

[](#rename-primary-key)

Change your primary key of a table. This has no effect on the primary key that was defined by the options.

```
$novus->table('users')->renamePrimaryKey('number');
```

Last And First
--------------

[](#last-and-first)

```
$first = $novus->table('users')->first();
echo $first['username'];

$last = $novus->table('users')->last();
echo $last['username'];
```

Find And FindOrFail
-------------------

[](#find-and-findorfail)

Find data by primary key. If no data found, `find()` will return an empty array and `findOrFail()` will return an exception.

```
$find = $novus->table('users')->find(1);
echo $find['username'];

$find = $novus->table('users')->findOrFail(2);
echo $find['username'];
```

ToDo
----

[](#todo)

- Finish `where()` conditions.
- Types for fields.
- Write tests.
- Own autoloader.
- Object access.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cf89a09eb544692f25528e91048101a8e235465a1fcec70f64461fb283cb45c?d=identicon)[devfake](/maintainers/devfake)

---

Top Contributors

[![devfake](https://avatars.githubusercontent.com/u/2204770?v=4)](https://github.com/devfake "devfake (46 commits)")

### Embed Badge

![Health badge](/badges/devfake-novus/health.svg)

```
[![Health](https://phpackages.com/badges/devfake-novus/health.svg)](https://phpackages.com/packages/devfake-novus)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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