foxtool / debra
Small ORM for the small projects
v1.0.0
2022-01-24 22:10 UTC
This package is not auto-updated.
Last update: 2025-06-16 12:48:33 UTC
README
Simply ORM for the simply projects
The Database class is used for the database connection.
This class is using the "configs/database.php"
file with the next structure:
return [ "host" => "localhost", "port" => 3306, "database" => "<database>", "username" => "<username>", "password" => "<password>" ];
Basic example
use FoxTool\Debra\EntityManager; // User class, defined for example in the "app/Entity/User.php" file use Debra\Entity\User; // Create EntityManager instance $em = new EntityManager(); // Set Model and return single object $user = $em->setModel(User::class)->find(1); // Display user login echo $user->getLogin(); // Display the generated query text $em->getQuery();
Examples:
Find record by ID
use FoxTool\Debra\EntityManager; // User class, defined for example in the "app/Entity/User.php" file use Debra\Entity\User; $em = new EntityManager(); $user = $em->setModel(User::class)->find(1);
Find all records
use FoxTool\Debra\EntityManager; // User class, defined for example in the "app/Entity/User.php" file use Debra\Entity\User; $em = new EntityManager(); $users = $em->setModel(User::class)->all();
The method all()
returns array of objects of the User
class
Find records by certain conditions
use FoxTool\Debra\EntityManager; // User class, defined for example in the "app/Entity/User.php" file use Debra\Entity\User; $em = new EntityManager(); $users = $em->setModel(User::class)->where([ "login = :login", "password = :password", "role = :role" ])->setParams([ "login" => "bob", "password" => "12345678", "role" => "author" ])->get();
The method get()
returns array of objects of the User
class
Create new record
$em = new EntityManager(); $em->setModel(User::class); $user = new User(); $user->setLogin('john'); $user->setPassword('12345678'); $user->setEmail('john.doe@gmail.com'); $user->setCreatedAt(date("Y-m-d H:i:s")); $user->setUpdatedAt(date("Y-m-d H:i:s")); $em->persist($user); $em->save();
Update record
$em = new EntityManager(); $user = $em->setModel(User::class)->find(1); $user->setLogin('john'); $user->setPassword('12345678'); $user->setEmail('john.doe@gmail.com'); $user->setCreatedAt(date("Y-m-d H:i:s")); $user->setUpdatedAt(date("Y-m-d H:i:s")); $em->persist($user); $em->save();