{"id":15890303,"url":"https://github.com/jacked-php/lite-connect","last_synced_at":"2026-01-25T01:31:41.588Z","repository":{"id":255440460,"uuid":"851223629","full_name":"Jacked-PHP/lite-connect","owner":"Jacked-PHP","description":"Lightweight SQLite package for PHP","archived":false,"fork":false,"pushed_at":"2024-10-24T02:26:45.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T15:49:12.312Z","etag":null,"topics":["php","sqlite"],"latest_commit_sha":null,"homepage":"","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/Jacked-PHP.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["jacked-php"]}},"created_at":"2024-09-02T16:59:59.000Z","updated_at":"2024-10-24T02:26:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb014bca-6eda-4312-aae0-caf8910665ba","html_url":"https://github.com/Jacked-PHP/lite-connect","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"198fee9819b622e66a6697016dab069c98f31215"},"previous_names":["jacked-php/lite-connect"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jacked-PHP%2Flite-connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jacked-PHP%2Flite-connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jacked-PHP%2Flite-connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jacked-PHP%2Flite-connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jacked-PHP","download_url":"https://codeload.github.com/Jacked-PHP/lite-connect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244126797,"owners_count":20402179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["php","sqlite"],"created_at":"2024-10-06T07:05:06.088Z","updated_at":"2026-01-25T01:31:41.571Z","avatar_url":"https://github.com/Jacked-PHP.png","language":"PHP","funding_links":["https://github.com/sponsors/jacked-php"],"categories":[],"sub_categories":[],"readme":"\n# LiteConnect\n\n[![Tests](https://github.com/Jacked-PHP/lite-connect/actions/workflows/php.yml/badge.svg)](https://github.com/Jacked-PHP/lite-connect/actions/workflows/php.yml)\n\nLiteConnect is a simple, lightweight SQLite package for PHP without globals. It is designed to facilitate easy and efficient SQLite database interactions. It is ideal for small to medium-sized projects that require an embedded database solution. This package provides a clean API for managing SQLite connections, running migrations, and interacting with your data models.\n\n## Features\n\n- **Connection Management**: Create and manage SQLite connections.\n- **Migration Management**: Run migrations to set up your database schema.\n- **Model Interaction**: Perform common database operations like `create`, `find`, `update`, `delete`, `where`, and `orderBy` through an intuitive API.\n\n## Installation\n\nTo install LiteConnect, you can require it via Composer:\n\n```bash\ncomposer require jacked-php/lite-connect\n```\n\n## Basic Usage\n\n### Connecting to a SQLite Database\n\n```php\nuse JackedPhp\\LiteConnect\\Connection\\Connection;\nuse JackedPhp\\LiteConnect\\SQLiteFactory;\n\n/** @var Connection $connection */\n$connection = SQLiteFactory::make([\n    'database' =\u003e 'path/to/your/database.db',\n]);\n\n// When you're done with the connection:\n$connection-\u003eclose();\n```\n\n### Running Migrations\n\nTo set up your database schema, use the `MigrationManager` to run migrations.\n\nExample with a \"users\" table migration:\n\n```php\nuse JackedPhp\\LiteConnect\\Migration\\MigrationManager;\n\nclass CreateUsersTable implements Migration\n{\n\n    public function up(PDO $pdo): void\n    {\n        $pdo-\u003eexec('CREATE TABLE users (\n            id INTEGER PRIMARY KEY AUTOINCREMENT,\n            name TEXT NULL,\n            email TEXT NOT NULL,\n            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n        )');\n    }\n\n    public function down(PDO $pdo): void\n    {\n        $pdo-\u003eexec('DROP TABLE users');\n    }\n}\n\n$migrationManager = new MigrationManager($connection);\n$migrationManager-\u003erunMigrations([\n    new CreateUsersTable(),\n]);\n```\n\n### Interacting with Models\n\nYou can interact with your data using the model classes. Here is an example of a `User` model:\n\n```php\nuse JackedPhp\\LiteConnect\\Model\\BaseModel;\n\nclass User extends BaseModel\n{\n    protected string $table = 'users';\n\n    protected ?string $primaryKey = 'id';\n\n    /**\n     * @var string[] $fillable\n     */\n    protected array $fillable = [\n        'name',\n        'email',\n    ];\n}\n\n\n// Creating a new user\n/** @var User $newUser */\n$newUser = (new User($connection))-\u003ecreate([\n    'name' =\u003e 'John Doe',\n    'email' =\u003e 'john.doe@example.com',\n]);\n\n// Finding a user by ID\n/** @var User $foundUser */\n$foundUser = (new User($connection))-\u003efind($newUser-\u003eid);\n\n// Updating a user\n$foundUser-\u003eupdate([\n    'email' =\u003e 'john.doe@newdomain.com',\n]);\n\n// Deleting a user\n$foundUser-\u003edelete();\n// or\n(new User($connection))-\u003ewhere('name', '=', 'John Doe')-\u003edelete();\n```\n\n### Querying Data\n\nYou can use the `where`, `orderBy`, and other query methods to filter and order your data:\n\n```php\n$users = new User($connection);\n\n$filteredUsers = $users-\u003ewhere('name', '=', 'John Doe')-\u003eget();\n// or\n$orderedUsers = $users-\u003eorderBy('id', 'desc')-\u003eget();\n```\n\n## Using a Connection Pool\n\n\u003e This example demonstrate how to do so with OpenSwoole - that is not a requirement for this package.\n\nIf your project is using `OpenSwoole\\Core` package (https://github.com/openswoole/core), here is how you accomplish it:\n\n```php\nuse OpenSwoole\\Core\\Coroutine\\Pool\\ClientPool;\n\n$connectionPool = new ClientPool(\n    factory: SQLiteFactory::class,\n    config: [\n        'database' =\u003e 'path/to/your/database.db',\n    ],\n    size: 1,\n);\n\n// here you get the connection:\n$connection = $connectionPool-\u003eget();\n\n// here you put back the connection:\n$connectionPool-\u003eput($connection);\n```\n\n## Testing\n\nYou can run tests by running the following after cloning the repository and installing dependencies:\n\n```bash\nvendor/bin/pest\n```\n\n## Contributing\n\nIf you would like to contribute to LiteConnect, please feel free to submit pull requests or open issues on the [GitHub repository](https://github.com/Jacked-PHP/lite-connect).\n\n## License\n\nLiteConnect is open-sourced software licensed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacked-php%2Flite-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacked-php%2Flite-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacked-php%2Flite-connect/lists"}