Download the PHP package tomvlk/sweet-orm without Composer
On this page you can find all versions of the php package tomvlk/sweet-orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sweet-orm
SweetORM
Simple and PHP orm, without having to use command line generators and migrators, can work on your existing table structure.
Configure and connecting
To start using the SweetORM you need to configure it, the whole back runs on PDO and needs to have a connection or configuration.
Inject PDO Connection
Only if you already have a PDO connection ready to the targetted database you could inject it.
Configuring for separate connection
When you don't have a PDO connection you need to setup the configuration of your database before touching any of the entities
Defining Entities
Entities are PHP class declarations made up on your database table structure. You need to extend the abstract Entity in SweetORM and use the Annotations available in SweetORM.
Other example, defining the Category entity:
Reading from database
Reading and searching from the database is very easy, you have two options for reading.
Get by primary key
Get a single Entity you requested back with the primary key value you ask for. Easy and fast:
Find by Query (Query Builder)
The ORM has a build-in query building option you could easy trigger with the static method find() on the Entity class
More information about the Query Builder will be available at the section Query Building.
Saving
Saving to the database is easy. To create a new instance of a entity, just create a new Entity object like this:
Creating new Entity
Then set all the properties:
And finally to save:
Changing Entity
To change an existing or fetched entity, just change the property value and use again.
Delete Entity
To delete the entity from the database use the method on the entity.
Query Builder
For finding the entity you could use the Query Builder. This will interactively build a SQL Query without knowing the exact syntax for the database.
Selecting Entity
Selecting entity with several query builder operations:
This is the same as the following query:
Builder Methods
Methods to build your query:
Of course you can chain all operations on the query builder.
Validation and filling
Validation against null and non-null, types and constraints (defined as annotations) could make using the ORM in REST environments way better.
Define constraints
You can use the following constraints:
- minLength: Minimum character length. Number.
- maxLength: Maximum character length. Number.
- minValue: Minimum int/float/double value to test against. Number.
- maxValue: Maximum int/float/double value to test against. Number.
- valid: Validate special cases. Can be 'email', 'url'. String.
- regex: Regular expression, will be tested against preg_match(). String.
- enum: Must be in the array given. Array of strings.
- startsWith: Test if string starts with. String
- endsWith: Test if string ends with. String
Test constraints and requirements
Filling and creating entities with raw data
Creating from the validator:
Update with data provided by the validator
Remember, by default the primary key(s) can't be overwritten by validator data!
All versions of sweet-orm with dependencies
doctrine/annotations Version ^1.10.2
doctrine/collections Version ^1.6.4