Download the PHP package jpi/orm without Composer

On this page you can find all versions of the php package jpi/orm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package orm

ORM

CodeFactor Latest Stable Version Total Downloads Latest Unstable Version License GitHub last commit (branch)

A super simple & lightweight ORM following the active record pattern.

This has been kept very simple stupid (KISS), with minimal validation (PHP type errors only) to reduce complexity in the library and maximize performance for consumer developers. Therefore, please make sure to add your own validation if using user inputs in any database queries.

Features

Dependencies

Installation

Use Composer

Properties and Methods for Setup

You will need to extend \JPI\ORM\Entity and then define the following:

getDatabase(): \JPI\Database

This method must be implemented to provide the database connection for this entity. \JPI\Database is just an extension of PDO - you can find out more here.

$table: string

The database table name for this entity.

$dataMapping: array

This array defines the structure of your entity and maps to your database columns. Each key is a column name and the value is an array with:

$columnPrefix: string - optional

Some database designers like to prefix their table columns. For example, the products table might have columns like product_id & product_name instead of id & name. Set this property to add that prefix automatically.

Note: the first underscore is required.

$defaultOrderByColumn: string - optional

The default column to order results by when selecting records and haven't specified an order. Default is id.

$defaultOrderByASC: bool - optional

Whether the default ordering should be ascending. Default is true.

Complete Example

Relationships

The ORM supports three types of relationships:

belongs_to - Many-to-One

has_many - One-to-Many

has_one - One-to-One

Usage

Retrieving Entities

getById(int $id): ?static - Get an entity by its ID.

newQuery(): QueryBuilder - Get a query builder instance for advanced queries. See Query Builder section for examples.

Accessing Entity Data

You can get and set entity values using simple property access, these are the keys from $dataMapping. When setting the value must be value for the type defined or null.

Creating and Saving Entities

factory(?array $data = null): static - Create a new entity instance, and optionally set initial data in one call.

insert(array $data): static - Create and save an entity in one call.

save(): bool - Save (insert or update) the entity to the database.

Deleting Entities

delete(): bool - Delete the entity from the database.

Utility Methods

isLoaded(): bool - Check if the entity has been loaded from or saved to the database.

isDeleted(): bool - Check if the entity has been deleted.

toArray(): array - Convert the entity to an array.

reload(): void - Reload the entity from the database.

Query Builder

The query builder (accessed via newQuery()) provides a fluent interface for building database queries. It uses \JPI\Database\Query\Builder from jpi/query, see documentation there for full details on available query methods.

Eager Loading

To avoid N+1 query problems, you can eager load relationships using the with() method:

Without eager loading, accessing relationships causes a separate query for each entity (N+1 problem). With eager loading, all related entities are fetched in a single optimized query.

Lazy Eager Loading

If you already have a collection of entities and later need to load relationships, use the load() method:

This is useful when you receive a collection from another part of your application and need to load relationships efficiently. Like with(), it prevents N+1 query problems by batching relationship queries instead of loading them one at a time.

Support

If you found this library interesting or useful please spread the word about this library: share on your socials, star on GitHub, etc.

If you find any issues or have any feature requests, you can open a issue or email me @ jahidulpabelislam.com :smirk:.

Authors

Licence

This module is licensed under the General Public Licence - see the licence file for details.


All versions of orm with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
jpi/utils Version ^1.0
jpi/database Version ^2.0
jpi/query Version ^2.2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jpi/orm contains the following files

Loading the files please wait ...