https://github.com/alexsoft-software/jsql
JSQLDB is a "lightweight, JSON-powered database system" designed for PHP applications. It provides "SQL-like queries" with the flexibility of JSON storage, "eliminating the need" for traditional database dependencies like SQLite or MySQL.
https://github.com/alexsoft-software/jsql
ascoos ascoos-framework database json php8 sql
Last synced: about 1 year ago
JSON representation
JSQLDB is a "lightweight, JSON-powered database system" designed for PHP applications. It provides "SQL-like queries" with the flexibility of JSON storage, "eliminating the need" for traditional database dependencies like SQLite or MySQL.
- Host: GitHub
- URL: https://github.com/alexsoft-software/jsql
- Owner: alexsoft-software
- License: other
- Created: 2025-04-22T02:03:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-22T21:22:56.000Z (about 1 year ago)
- Last Synced: 2025-04-22T22:24:42.426Z (about 1 year ago)
- Topics: ascoos, ascoos-framework, database, json, php8, sql
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE_AGL-F.md
Awesome Lists containing this project
README
# **JSQLDB - JSON SQL Database for PHP**
## π¬ **A lightweight, SQL-like JSON-based database for PHP**
**JSQLDB** is a **flexible database system** that **leverages JSON** for storage and provides **SQL-like queries** without requiring SQLite or MySQL. Itβs **lightweight, fast**, and **perfect** for applications that need **portability and security**.
---

---
### π **Features**
- β
**JSON-based storage** without DLL/SO dependencies
- β
**SQL-like queries** with support for `SELECT`, `INSERT`, `UPDATE`, `DELETE`, `JOIN`, `UNION`, `GROUP BY`, `HAVING`, `LIMIT`, `ORDER BY`, `DISTINCT` etc.
- β
**Indexing support** for fast searching
- β
**Compressed storage** for optimized resource usage
- β
**Customizable storage path** for secure data management
- β
**Optimized for PHP 8.2+**
---
### π§© Requires:
- PHP 8.2+
- Ascoos Framework (For high level access, and managed)
- ionCube Loaders
---
### **π» Installation**
```bash
git clone https://github.com/alexsoft-software/jsql.git
cd jsql
composer install
```
βοΈ **More details coming soon in the documentation!**
---
## π **Using the Database**
The database must be initialized before using it. This is done through the settings file.
### **π Example Settings**
```php
return [
'jsql' => [
'config_path' => '/root/path/conf/config.json',
'users_path' => '/root/path/conf/users.json',
'databases_root_path' => '/root/path/jsql_db',
]
];
```
### **π Example Usage**
```php
createDatabase('test_db');
// Create User and assign to Database
$jsql->createUser('admin', 'root', 'test_db');
// Select Current Database
$jsql->select_db('test_db');
// Create Table
$sql = "CREATE TABLE `#__articles` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`article_id` INT UNSIGNED NOT NULL DEFAULT 0,
`cat_id` INT UNSIGNED NOT NULL DEFAULT 0,
`user_id` INT UNSIGNED NOT NULL DEFAULT 0,
`lang_id` INT UNSIGNED NOT NULL DEFAULT 0,
`title` VARCHAR(200) NOT NULL,
`content` TEXT NULL COMPRESSED,
`created` DATETIME NULL DEFAULT CURRENT_TIMESTAMP(),
`updated` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP()
);";
$jsql->setSQLQuery($sql);
$jsql->execute();
// Insert Data
$query->setSQLQuery("INSERT INTO #__articles (article_id, cat_id, user_id, lang_id, title, content) VALUES
(1, 1, 1, 1, 'Title 1', 'Test Content 1'),
(1, 1, 1, 2, 'Title 2', 'Test Content 2'),
(2, 2, 1, 1, 'Title 3', 'Test Content 3'),
(3, 3, 1, 1, 'Title 4', 'Test Content 4'),
(3, 1, 1, 2, 'Title 5', 'Test Content 5');
");
$query->execute();
$query = "SELECT article_id AS aid, title, content AS doc FROM #__articles WHERE user_id = ".$my->id." AND lang_id = 1 ORDER BY created DESC LIMIT 10";
$jsql->setSQLQuery($query);
$jsql->execute();
$data = $jsql->getResults();
// Close all open database resources
$jsql->close();
print_r($data);
?>
```
### π **Alternative way to create a table**
```php
// Direct way to create a table and its structure.
$schema = [
'id' => 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY',
'article_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
'cat_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
'user_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
'lang_id' => 'INT UNSIGNED NOT NULL DEFAULT 0',
'title' => 'VARCHAR(200) NOT NULL',
'content' => ' TEXT NULL COMPRESSED',
'created' => ' DATETIME NULL DEFAULT CURRENT_TIMESTAMP()',
'updated' => 'DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP()'
];
$jsql->createTable('#__articles', $schema);
```
βοΈ **See more examples on the official website!**