sandeshshrestha / tiny-orm
Tiny ORM to map between objects and database queries
1.4
2021-12-25 14:49 UTC
This package is auto-updated.
Last update: 2024-05-25 20:08:31 UTC
README
Installation
composer require sandeshshrestha/tiny-orm
Configuration
Define few constants.
// Define __FILE_STORAGE_PATH__ constant where the FileStorage::save() method saves the file. define("__FILE_STORAGE_PATH__", __DIR__ . '/uploaded_files/'); // Define __DATABASE_CONFIG__ constant that will be used by Database.php to connect to database define("__DATABASE_CONFIG__", [ 'type' => 'mysql', 'host' => 'mysql.example.com', 'username' => 'db_username', 'password' => 'db_password', 'database' => 'db_name', 'table_prefix' => 'db_table_prefix', 'port' => 3306 ]);
Database
Create database tables
CREATE TABLE `db_table_prefix_user` ( `id` varchar(255) NOT NULL, `fullName` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Usage
use TinyORM\Model; class User extends Model { protected $table = 'user'; protected $primaryKey = 'id'; protected $fillable = ["fullName", "email"]; } $user = new User(); $user->fullName = "John Doe"; $user->email = "johndoe@example.com"; $user->save(); $user2 = User::create([ 'fullName' => "John Doe 2", "email" => "johndoe2@example.com", ]); $foundUser = User::find($user->getPrimaryValue()); $foundUser->delete(); $users = User::where("fullName", "John Doe")->limit(1)->orderBy('id')->exec();
Documentations
https://sandeshshrestha.github.io/PHP-Tiny-ORM/