PHPackages                             wowoengine/sawitdb-php - 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. wowoengine/sawitdb-php

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

wowoengine/sawitdb-php
======================

PHP Port of SawitDB Node.JS Version - A single-file NoSQL database for PHP.

v1.0.0(4mo ago)20371MITPHPPHP ^8.0

Since Jan 5Pushed 4mo agoCompare

[ Source](https://github.com/WowoEngine/SawitDB-PHP)[ Packagist](https://packagist.org/packages/wowoengine/sawitdb-php)[ RSS](/packages/wowoengine-sawitdb-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

SawitDB (PHP Version)
=====================

[](#sawitdb-php-version)

[![SawitDB Banner](https://github.com/WowoEngine/SawitDB/raw/main/docs/sawitdb.jpg)](https://github.com/WowoEngine/SawitDB/raw/main/docs/sawitdb.jpg)

[![Docs](https://camo.githubusercontent.com/5c0cb9287d70e3d8781a1126b1060392e5f46e3d8e201ed5d3cf243e16804c97/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f63732d526561642532304e6f772d626c75653f7374796c653d666f722d7468652d6261646765266c6f676f3d676f6f676c65646f6373)](https://wowoengine.github.io/SawitDB/)[![Packagist](https://camo.githubusercontent.com/50b07853ef280b544ee75b1e45d3358d3fc31112bbbf167b970050ce555b6907/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776f776f656e67696e652f736177697464622d7068703f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374)](https://packagist.org/packages/wowoengine/sawitdb-php)[![Node.js Version](https://camo.githubusercontent.com/e1b5ad7937d9be2c017dbb22d03b2d9b8557779b37812258902dd908df92877f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4e6f64652e6a7325323056657273696f6e2d56697369742532305265706f2d677265656e3f7374796c653d666f722d7468652d6261646765266c6f676f3d6e6f6465646f746a73)](https://github.com/WowoEngine/SawitDB)[![Go Version](https://camo.githubusercontent.com/efa5acda9d3adbf504ce26de2eda58a68369c3355f998965a587cd3615115408/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f476f25323056657273696f6e2d56697369742532305265706f2d6379616e3f7374796c653d666f722d7468652d6261646765266c6f676f3d676f)](https://github.com/WowoEngine/SawitDB-Go)

**SawitDB** is a unique database solution stored in `.sawit` binary files.

The system features a custom **Paged Heap File** architecture similar to SQLite, using fixed-size 4KB pages to ensure efficient memory usage. What differentiates SawitDB is its unique **Agricultural Query Language (AQL)**, which replaces standard SQL keywords with Indonesian farming terminology.

**Now availability on Packagist!**

**🚨 Emergency: Aceh Flood Relief**Please support our brothers and sisters in Aceh.

[![Kitabisa](https://camo.githubusercontent.com/97e7a481257c3ca550bf7f5c3243890882b6ac4a2b1b57bc5c7f6844774d678e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4b697461626973612d42616e7475253230416365682d626c75653f7374796c653d666c6174266c6f676f3d6865617274)](https://kitabisa.com/campaign/donasipedulibanjiraceh)

*Organized by Human Initiative Aceh*

Features
--------

[](#features)

- **Paged Architecture**: Data is stored in 4096-byte binary pages.
- **Object Caching (New)**: Implements Page-Level Object Caching for high-speed reads (bypassing JSON parse for hot pages).
- **Hash Joins (New)**: Optimized `JOIN` operations (O(M+N)) for massive performance gains on relations.
- **Persistent Indexes (New)**: Indexes are now automatically persisted in `_indexes` system table and restored on load.
- **Query Cache (New)**: LRU Cache for parsed queries to reduce CPU overhead.
- **Zero Bureaucracy**: Built with **standard PHP**. No massive vendor dependencies.
- **Network Support**: Client-Server architecture using PHP Streams.

Philosophy
----------

[](#philosophy)

### Filosofi (ID)

[](#filosofi-id)

SawitDB dibangun dengan semangat "Kemandirian Data". Kami percaya database yang handal tidak butuh **Infrastruktur Langit** yang harganya triliunan tapi sering *down*. Berbeda dengan proyek negara yang mahal di *budget* tapi murah di kualitas, SawitDB menggunakan arsitektur **Single File** (`.sawit`) yang hemat biaya. Backup cukup *copy-paste*, tidak perlu sewa vendor konsultan asing. Fitur **`fsync`** kami menjamin data tertulis di *disk*, karena bagi kami, integritas data adalah harga mati.

### Philosophy (EN)

[](#philosophy-en)

SawitDB is built with the spirit of "Data Sovereignty". We believe a reliable database doesn't need **"Sky Infrastructure"** that costs trillions yet goes *down* often. Unlike state projects that are expensive in budget but cheap in quality, SawitDB uses a cost-effective **Single File** (`.sawit`) architecture. Backup is just *copy-paste*.

Installation
------------

[](#installation)

Install via Composer:

```
composer require wowoengine/sawitdb-php
```

Framework Support
-----------------

[](#framework-support)

### Vanilla PHP &amp; CodeIgniter 4

[](#vanilla-php--codeigniter-4)

SawitDB acts as a standard PSR-4 library. You can use the `WowoEngine` directly or connect via the Client.

```
use SawitDB\Engine\WowoEngine;
$db = new WowoEngine(__DIR__ . '/plantation.sawit');
```

### Laravel Integration

[](#laravel-integration)

SawitDB includes a ServiceProvider and Facade for seamless Laravel integration.

1. **Install via Composer**: `composer require wowoengine/sawitdb-php`
2. **Configuration**: Publish the config or add to `config/database.php`.

```
// config/database.php
'connections' => [
    'sawit' => [
        'database' => env('SAWIT_DB_DATABASE', database_path('plantation.sawit')),
    ],
],
```

3. **Usage**:

```
use SawitDB;

// In Controller
public function index() {
    SawitDB::query("LAHAN users");
    SawitDB::query("TANAM KE users (name) BIBIT ('Budi')");
    return SawitDB::query("PANEN * DARI users");
}
```

Quick Start (Network Edition)
-----------------------------

[](#quick-start-network-edition)

### 1. Start the Server

[](#1-start-the-server)

```
php bin/sawit-server.php
```

The server will start on `0.0.0.0:7878` by default.

### 2. Connect with Client (CLI)

[](#2-connect-with-client-cli)

```
php cli/remote.php sawitdb://localhost:7878/my_plantation
```

---

Usage (Embedded)
----------------

[](#usage-embedded)

You can use the `WowoEngine` directly in your PHP applications.

```
use SawitDB\Engine\WowoEngine;

$db = new WowoEngine(__DIR__ . '/plantation.sawit');

// Generic SQL
$db->query("CREATE TABLE users");
$db->query("INSERT INTO users (id, name) VALUES (1, 'Budi')");

// AQL
$db->query("LAHAN trees");
$db->query("TANAM KE trees (id, type) BIBIT (1, 'Dura')");

// Join
$rows = $db->query("SELECT * FROM trees JOIN users ON trees.id = users.id");
print_r($rows);
```

Architecture Details
--------------------

[](#architecture-details)

- **Modular Codebase**: Engine logic separated into `src/` components.
- **Page 0 (Master Page)**: Contains header and Table Directory.
- **Data &amp; Indexes**: Stored in 4KB atomic pages.
- **WowoEngine**: Core engine orchestrating Pager, Index, and Query Parser.

Full Feature Comparison
-----------------------

[](#full-feature-comparison)

FeatureTani Edition (AQL)Generic SQL (Standard)Notes**Create DB**`BUKA WILAYAH [db]``CREATE DATABASE [db]`Creates `.sawit` in data/**Use DB**`MASUK WILAYAH [db]``USE [db]`Switch context**Show DBs**`LIHAT WILAYAH``SHOW DATABASES`Lists available DBs**Drop DB**`BAKAR WILAYAH [db]``DROP DATABASE [db]`**Irreversible!****Create Table**`LAHAN [table]``CREATE TABLE [table]`Schema-less creation**Show Tables**`LIHAT LAHAN``SHOW TABLES`Lists tables in DB**Drop Table**`BAKAR LAHAN [table]``DROP TABLE [table]`Deletes table &amp; data**Insert**`TANAM KE [table] ... BIBIT (...)``INSERT INTO [table] (...) VALUES (...)`Auto-ID if omitted**Select**`PANEN ... DARI [table] DIMANA ...``SELECT ... FROM [table] WHERE ...`Supports Projection**Join**`... GABUNG [tbl] PADA ...``... JOIN [tbl] ON ...`Hash/Nested Loop**Update**`PUPUK [table] DENGAN ... DIMANA ...``UPDATE [table] SET ... WHERE ...`Atomic update**Delete**`GUSUR DARI [table] DIMANA ...``DELETE FROM [table] WHERE ...`Row-level deletion**Index**`INDEKS [table] PADA [field]``CREATE INDEX ON [table] (field)`B-Tree Indexing**Count**`HITUNG COUNT(*) DARI [table]``SELECT COUNT(*) FROM [table]` (via HITUNG)Aggregation### Supported Operators Table

[](#supported-operators-table)

OperatorSyntax ExampleDescription**Comparison**`=`, `!=`, `>`, `=`, `
