{"id":22812506,"url":"https://github.com/mathsgod/light-db","last_synced_at":"2026-03-04T05:04:50.073Z","repository":{"id":266433274,"uuid":"898347864","full_name":"mathsgod/light-db","owner":"mathsgod","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-27T09:43:48.000Z","size":192,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-27T15:06:58.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathsgod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-04T08:30:43.000Z","updated_at":"2026-02-27T09:43:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"6c4ced30-40e2-498a-9048-7d27425828d8","html_url":"https://github.com/mathsgod/light-db","commit_stats":null,"previous_names":["mathsgod/light-db"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/mathsgod/light-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Flight-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Flight-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Flight-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Flight-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathsgod","download_url":"https://codeload.github.com/mathsgod/light-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Flight-db/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30071909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T03:25:38.285Z","status":"ssl_error","status_checked_at":"2026-03-04T03:25:05.086Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T12:12:58.302Z","updated_at":"2026-03-04T05:04:50.044Z","avatar_url":"https://github.com/mathsgod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub](https://img.shields.io/github/license/mathsgod/light-db)](https://github.com/mathsgod/light-db)\n[![PHP](https://img.shields.io/badge/PHP-8.1%2B-blue.svg)](https://www.php.net/)\n[![Tests](https://img.shields.io/badge/tests-73%20passing-brightgreen.svg)](https://github.com/mathsgod/light-db)\n\n# Light-DB\n\nLight-DB is a lightweight PHP ORM/database access layer built on top of Laminas DB, designed for modern PHP 8.1+ applications. It provides an Eloquent-like Model operation experience with support for auto-mapping, dynamic queries, relationship queries, JSON field operations, and pagination features.\n\n## ✨ Features\n\n- 🚀 **Modern PHP**: Built on PHP 8.1+ features with type declarations and modern PHP syntax\n- 🔗 **Multi-Database Support**: Based on Laminas DB, supports MySQL, PostgreSQL, SQLite, SQL Server and more\n- 📦 **Eloquent-Style**: Familiar Active Record pattern with Eloquent-like API\n- 🎯 **Smart Queries**: Support for complex conditional queries, sorting, grouping, and aggregation functions\n- 📄 **Pagination Support**: Built-in Laminas Paginator integration for easy pagination\n- 🔄 **JSON Fields**: Native support for JSON field operations with automatic serialization/deserialization\n- 🔗 **Relationship Queries**: Support for inter-model relationship queries and dynamic property access\n- 🧪 **Comprehensive Testing**: 73+ test cases ensuring code quality and stability\n- ⚡ **High Performance**: Lazy loading and query optimization for excellent performance\n\n## 📋 Requirements\n\n- PHP 8.1 or higher\n- PDO extension\n- Supported databases: MySQL, PostgreSQL, SQLite, SQL Server, etc.\n\n## 🚀 Installation\n\nInstall via Composer:\n\n```bash\ncomposer require mathsgod/light-db\n```\n\n## ⚙️ Configuration\n\nCreate a `.env` file in your project root:\n\n```env\nDATABASE_DRIVER=pdo_mysql\nDATABASE_HOSTNAME=localhost\nDATABASE_PORT=3306\nDATABASE_DATABASE=your_database\nDATABASE_USERNAME=your_username\nDATABASE_PASSWORD=your_password\nDATABASE_CHARSET=utf8mb4\n```\n\n## 🎯 Basic Usage\n\n### Defining Models\n\n```php\n\u003c?php\n\nuse Light\\Db\\Model;\n\nclass User extends Model\n{\n    // Uses class name as table name by default\n    // Customize with: protected static $_table = 'custom_table_name';\n}\n\nclass Post extends Model\n{\n    protected static $_table = 'posts';\n}\n```\n\n### CRUD Operations\n\n#### Creating Records\n\n```php\n// Method 1: Create + Save\n$user = User::Create([\n    'name' =\u003e 'Raymond Chong',\n    'email' =\u003e 'raymond@example.com',\n    'age' =\u003e 30\n]);\n$user-\u003esave();\n\n// Method 2: Direct property assignment\n$user = User::Create();\n$user-\u003ename = 'John Doe';\n$user-\u003eemail = 'john@example.com';\n$user-\u003esave();\n```\n\n#### Querying Records\n\n```php\n// Query by primary key\n$user = User::Get(1);\n\n// Basic queries\n$users = User::Query(['status' =\u003e 'active'])-\u003etoArray();\n\n// Complex queries\n$activeUsers = User::Query()\n    -\u003efilters([\n        'age' =\u003e ['gte' =\u003e 18, 'lte' =\u003e 65],\n        'status' =\u003e ['in' =\u003e ['active', 'premium']],\n        'email' =\u003e ['contains' =\u003e '@gmail.com']\n    ])\n    -\u003esort('created_at:desc')\n    -\u003etoArray();\n\n// Get first record\n$firstUser = User::Query(['status' =\u003e 'active'])-\u003efirst();\n```\n\n#### Updating Records\n\n```php\n// Single record update\n$user = User::Get(1);\n$user-\u003ename = 'Updated Name';\n$user-\u003eemail = 'updated@example.com';\n$user-\u003esave();\n\n// Batch update\n$affected = User::Query(['status' =\u003e 'inactive'])\n    -\u003eupdate(['status' =\u003e 'archived']);\n```\n\n#### Deleting Records\n\n```php\n// Single record deletion\n$user = User::Get(1);\n$user-\u003edelete();\n\n// Batch deletion\n$deleted = User::Query(['status' =\u003e 'spam'])\n    -\u003edelete();\n```\n\n### 🔍 Advanced Queries\n\n#### Query Conditions\n\n```php\n$query = User::Query()-\u003efilters([\n    'age' =\u003e ['eq' =\u003e 25],           // Equal to\n    'score' =\u003e ['gt' =\u003e 80],         // Greater than\n    'salary' =\u003e ['gte' =\u003e 50000],    // Greater than or equal\n    'rating' =\u003e ['lt' =\u003e 5],         // Less than\n    'points' =\u003e ['lte' =\u003e 100],      // Less than or equal\n    'status' =\u003e ['in' =\u003e ['active', 'premium']], // In array\n    'name' =\u003e ['contains' =\u003e 'john'],  // Contains pattern\n    'category' =\u003e ['ne' =\u003e 'spam']   // Not equal\n]);\n```\n\n#### Sorting and Limiting\n\n```php\n$users = User::Query()\n    -\u003esort('created_at:desc,name:asc')  // Multi-field sorting\n    -\u003elimit(10)                         // Limit results\n    -\u003eoffset(20)                        // Offset\n    -\u003etoArray();\n```\n\n#### Aggregate Functions\n\n```php\n$userCount = User::Query()-\u003ecount();\n$avgAge = User::Query()-\u003eavg('age');\n$totalSalary = User::Query()-\u003esum('salary');\n$minAge = User::Query()-\u003emin('age');\n$maxAge = User::Query()-\u003emax('age');\n```\n\n### 📄 Pagination\n\n```php\n$query = User::Query(['status' =\u003e 'active']);\n$paginator = $query-\u003egetPaginator();\n\n// Set items per page\n$paginator-\u003esetItemCountPerPage(20);\n$paginator-\u003esetCurrentPageNumber(1);\n\n// Get current page data\n$currentItems = $paginator-\u003egetCurrentItems();\n$totalItems = $paginator-\u003egetTotalItemCount();\n$totalPages = $paginator-\u003egetPages()-\u003epageCount;\n```\n\n### 🔄 JSON Field Operations\n\n```php\n// Create record with JSON data\n$user = User::Create([\n    'name' =\u003e 'John',\n    'profile' =\u003e [\n        'avatar' =\u003e 'avatar.jpg',\n        'settings' =\u003e [\n            'theme' =\u003e 'dark',\n            'notifications' =\u003e true\n        ],\n        'tags' =\u003e ['developer', 'php', 'mysql']\n    ]\n]);\n$user-\u003esave();\n\n// Read JSON data\n$user = User::Get(1);\necho $user-\u003eprofile['settings']['theme']; // 'dark'\n\n// Update JSON data\n$user-\u003eprofile['settings']['theme'] = 'light';\n$user-\u003eprofile['tags'][] = 'javascript';\n$user-\u003esave();\n```\n\n### 🔗 Relationship Queries\n\n```php\n// Assuming UserList model with user_id column\n$user = User::Get(1);\n\n// Get related UserList query object\n$userLists = $user-\u003eUserList;  // Returns Query object\n\n// Further querying\n$activeLists = $user-\u003eUserList\n    -\u003efilters(['status' =\u003e 'active'])\n    -\u003esort('created_at:desc')\n    -\u003etoArray();\n```\n\n### 🛠️ Advanced Features\n\n#### Collection Operations\n\n```php\n$users = User::Query(['status' =\u003e 'active']);\n\n// Map operation\n$names = $users-\u003emap(fn($user) =\u003e $user-\u003ename)-\u003etoArray();\n\n// Filter operation\n$premiumUsers = $users-\u003efilter(fn($user) =\u003e $user-\u003etype === 'premium');\n\n// Method chaining\n$emailList = User::Query()\n    -\u003efilters(['status' =\u003e 'active'])\n    -\u003emap(fn($user) =\u003e $user-\u003eemail)\n    -\u003etoArray();\n```\n\n#### Custom Sorting\n\n```php\n// Register custom sorting logic\nUser::RegisterOrder('popular', function($query) {\n    return $query-\u003eorder(['score DESC', 'views DESC']);\n});\n\n// Use custom sorting\n$popularUsers = User::Query()-\u003esort('popular')-\u003etoArray();\n```\n\n## 📊 Available Test Groups\n\nThis project includes a comprehensive test suite. You can run specific test groups:\n\n```bash\n# Run all tests\ncomposer test\n\n# Run basic functionality tests\ncomposer test-basic\n\n# Run CRUD operation tests\ncomposer test-crud\n\n# Run JSON field tests\ncomposer test-json\n\n# Run unit tests\ncomposer test-unit\n\n# Run integration tests\ncomposer test-integration\n```\n\n## 🧪 Test Coverage\n\n- **73+** test cases\n- **269+** assertions\n- Covers all core functionality\n- Includes unit and integration tests\n- Supports error handling and edge case testing\n\n## 📝 License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## 👨‍💻 Author\n\n**Raymond Chong**\n- Email: mathsgod@yahoo.com\n- GitHub: [@mathsgod](https://github.com/mathsgod)\n\n## 🤝 Contributing\n\nIssues and Pull Requests are welcome!\n\n1. Fork the project\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📚 More Examples\n\nCheck the test files in the `tests/` directory for more usage examples and best practices.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Flight-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathsgod%2Flight-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Flight-db/lists"}