Download the PHP package jijihohococo/ichi-orm without Composer

On this page you can find all versions of the php package jijihohococo/ichi-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 ichi-orm

Ichi ORM

Ichi ORM aims to be a fast, secure database ORM for PHP that is simple to use.

License

This package is Open Source According to MIT license

Table of Contents

Installation

Set up Database Connection

This library can connect to MySQL, PostgreSQL, Microsoft SQL Server and SQLite.

First, you need to declare your database driver as shown below.

If you want to add another custom database connection, you can do so as shown below.

You must add dbname, host, user_name, and user_password to your database connection. We recommend using "utf8mb4" for the database charset and "utf8mb4_unicode_ci" for the database collation.

For the default database connections, you do not need to specify the driver parameter. For custom database connections, you must specify it.

The default database connections are 'mysql', 'pgsql', 'sqlsrv' and 'sqlite'.

The supported database drivers are 'mysql', 'pgsql', 'sqlsrv' and 'sqlite'.

After declaring the database connection, you can select the default database connection.

Available Database Setting

Name Description Required
driver Database driver name ✓
dbname Database name ✓
charset Charset Font
collation Collation Font Setting for MySQL and Postgres SQL
host Database Host Address ✓
user_name Database User Name ✓
user_password Database User Password ✓
unix_socket Unix Socket For MySQL
port Databse Port Number
strict (bool) Strict Mode In MySQL
time_zone Database Time Zone in MySQL and Postgres SQL
isolation_level To set Isolation Level in MySQL
modes (array) To set sql_mode in MySQL
synchronous_commit To set Synchronous Commit in Postgres SQL
sslmode To set SSL Mode in Postgres SQL
sslcert To set SSL Certificate in Postgres SQL
sslkey To set SSL Key in Postgres SQL
sslrootcert To set SSL Root Certificate in Postgres SQL
readOnly (bool) True To set ApplicationIntent to ReadOnly in MS SQL Server
pooling (bool) True To set ConnectionPooling to true in MS SQL Server
application_name To set APP in MS SQL Server OR application name in Postgres SQL
encrypt To set ENCRYPT in MS SQL Server
trust_server_certificate To set TrustServerCertificate in MS SQL Server
multiple_active_result_sets To set MultipleActiveResultSets in MS SQL Server
transaction_isolation To set TransactionIsolation in MS SQL Server
multi_subnet_failover To set MultiSubnetFailover in MS SQL Server
column_encryption To set ColumnEncryption in MS SQL Server
key_store_authentication To set KeyStoreAuthentication in MS SQL Server
key_store_principal_id TO set KeyStorePrincipalId in MS SQL Server
key_store_secret To set KeyStoreSecret in MS SQL Server
login_timeout To set LoginTimeout in MS SQL Server

Table Structure

If you have a column named "deleted_at", make sure that the column is nullable.

Create Model From Commandline

First, create a file named "ichi" in your project folder and add the following code to it:

You can then create a model from the command line:

The default model directory is "app/Models". After running the command, the model you created will be placed in this directory. If you want to change the default directory, you can change it in your "ichi" file.

Configuration Table Name

In Ichi ORM, one model class which is extended "JiJiHoHoCoCo\IchiORM\Database\Model" abstract class is represented one table.

By default, the table name for a model class follows the format below:

Model Table
Item items
OrderItem order_items

If the default format is not suitable for your model class, you can customize the table name in your model class:

Configuration Primary Key

By default, the primary key for the table is "id". If you want to change it, you can customize it in your model class:

CRUD

First, extend the Model class and declare your data fields as properties in your model, as shown below.

Create

You can create data as shown below.

You can choose whether or not to include nullable fields in the array passed to the "create" function.

If you have a "created_at" field, you do not need to provide a value for it. Ichi ORM automatically inserts the current date and time. The field must use the timestamp or varchar format.

You can get the new model object after creation.

App\Models\Blog Object ( [id] => 1 [author_id] => 1 [content] => Content [created_at] => 2021-10-01 12:02:26 [updated_at] => [deleted_at] => )

Disable Auto increment Id

If your table does not use an auto-incrementing ID, you must define this function in your model class:

You must then provide the ID value manually, as shown below:

Insert Multiple Rows In One Query

If you want to insert multiple rows with one query, you can do so as shown below.

Retrieve

You can retrieve data by its primary key as shown below.

If you do not want to retrieve data by the primary key, you can use the following:

The first parameter is the field name, and the second parameter is the value.

The "find" and "findBy" functions return only a single object.

Refers To

If you have a one-to-one relationship in your database, with or without foreign keys, you can use the "refersTo" function in the child model class as shown below. The function returns a single object.

If the parent model's primary key is "id", you must provide the parent model name and the field that represents the parent ID to the "refersTo" function.

If the parent model's primary key is not "id", you must provide the parent model name, the field that represents the parent ID, and the parent's primary key field to the "refersTo" function.

You can retrieve the parent data as a single object in your controller or class.

You do not need to handle null values manually; the relationship function provides null safety.

Refers Many

If you have a one-to-many relationship in your database, with or without foreign keys, you can use the "refersMany" function in the parent model class as shown below. The function returns an object array.

If the parent model's primary key is "id", you must provide the child model name and the field that represents the parent ID in the child model to the "refersMany" function.

If the parent model's primary key is not "id", you must provide the child model name, the field that represents the parent ID in the child model, and the parent's primary key field to the "refersMany" function.

You can customize the child query:

You can retrieve child data as an object array in your controller or class.

Update

You can update your data as shown below.

You can get the model object after updating.

If you have an "updated_at" field, you do not need to provide a value for it. Ichi ORM automatically inserts the current date and time. The field must use the timestamp or varchar format.

App\Models\Blog Object ( [id] => 1 [author_id] => 1 [content] => New Content [created_at] => 2021-10-01 12:02:26 [updated_at] => 2021-10-01 12:03:26 [deleted_at] => )

Update Multiple Rows In One Query

If you want to update multiple rows with one query, you can do so as shown below.

Delete

You can delete your data as shown below.

If you have a nullable "deleted_at" field, soft deletes are enabled. The data is not actually deleted; instead, it is excluded from queries by default.

Soft deletes cannot be used if you do not have a "deleted_at" field; in that case, the data is permanently deleted.

If you want to restore your soft-deleted data, you can do so as shown below.

If you want to permanently delete your data, whether or not it is configured for soft deletes, you can use the following:

Querying

SELECT

To build a "SELECT" SQL query, you can use the "select" function as shown below:

Getting Query Data

You can retrieve query data using the "get()" and "toArray()" functions.

Get

The "get()" function can be used in both main queries and subqueries. When used in a main query, it returns an array of model objects, as shown below.

Array ( [0] => App\Models\Blog Object ( [id] => 1 [author_id] => 1 [content] => Content [created_at] => 2021-10-01 12:02:26 [updated_at] => 2021-10-01 12:02:26 [deleted_at] => ) )

You can call relationship functions directly on the objects in the loop because "get()" returns an object array.

If you do not use the "select" function, you will get all fields of the related model.

To Array

The "toArray()" function can only be used in the main query. It returns the query results as an array, as shown below.

Array ( [0] => Array ( [id] => 1 [author_id] => 1 [content] => Content [created_at] => 2021-10-01 12:02:26 [updated_at] => 2021-10-01 12:02:26 [deleted_at] => ) )

You cannot call relationship functions directly on the objects in the loop because "toArray()" returns arrays.

You cannot use the "toArray()" function in a subquery.

If you do not use the "select" function, you will get all fields of the related model.

Get Query Data With Soft Deleted Data

If you have soft-deleted rows, they are not included in your arrays or object arrays by default. To include soft-deleted rows, use the "withTrashed()" function as shown below.

If you do not use the "select" function, you will get all fields of the related model. You will also get soft deleted data rows if you use "withTrashed()" function.

LIMIT

To add a LIMIT clause to a SQL query, use the "limit" function and pass an integer to it, as shown below.

In a main query:

In subquery:

WHERE

To add a "WHERE" clause to a SQL query, use the "where" function as shown below:

For the "=" operator:

To specify an operator:

OR WHERE

To add an "OR WHERE" clause to a SQL query, use the "orWhere" function as shown below:

For the "=" operator:

To specify an operator:

WHERE COLUMN

To compare the values of two columns instead of comparing a column with a value, use the "whereColumn()" function.

For an equality comparison:

You can also specify a comparison operator:

You can use qualified column names when comparing columns from different tables:

OR WHERE COLUMN

To compare two columns using an "OR" condition, use the "orWhereColumn()" function.

You can also specify a comparison operator:

Qualified column names can also be used:

WHERE IN

To add a "WHERE IN" clause to a SQL query, use the "whereIn" function as shown below:

OR WHERE IN

To add an "OR" condition that checks whether a column value matches any value in an array, use the "orWhereIn()" function.

You can also use a subquery:

WHERE NOT IN

To add a "WHERE NOT IN" clause to a SQL query, use the "whereNotIn" function as shown below:

OR WHERE NOT IN

To add an "OR" condition that checks whether a column value does not match any value in an array, use the "orWhereNotIn()" function.

You can also use a subquery:

Join

The syntax and behavior follow standard SQL JOIN syntax.

Inner Join

Single SQL query:

Subquery:

Left Join

Single SQL query:

Subquery:

Right Join

Single SQL query:

Subquery:

Union

You can use the "union" function in queries.

You can also use the "union" function in subqueries.

Pagination

This library supports two types of pagination:

  1. Database Pagination
  2. Array Pagination

The default number of items per page is 10. You can customize this number. The pagination functions return an array in the following format. You can use this array data for server-side pagination in your frontend application, such as Vue or React.

Database Pagination

You can paginate your query results as shown below:

You can customize the number of items per page:

You can access the paginated data as shown below. The value of the "data" key is an object array.

You can call relationship functions directly on the objects in the loop.

You can use the pagination UI in your frontend PHP file as follows:

You can customize the pagination UI color:

Array Pagination

You can paginate an array as shown below.

You can also use a multidimensional array:

You can customize the number of items per page:

You can use the pagination UI in your frontend PHP file as follows:

You can customize the pagination UI color:

Subqueries

If you want to use a subquery within the same table, you can do so as shown below.

You can use subqueries in the "where", "orWhere", and "whereIn" functions as shown below.

If you want to use a subquery from a different table, you can do so as shown below.

You can use the "from" function only in subqueries. You need to provide the model class name that represents the other table to the "from" function.

If you want to use a subquery in SELECT, you can use the "addSelect" and "addOnlySelect" functions.

The "addSelect" function adds a subquery to the SELECT query.

It selects the data returned by its function in addition to the data selected by the "select" function.

If you do not use the "select" function, it selects the data returned by its function in addition to all fields from the selected table.

You can't use "addSelect" function in subqueries

The "addOnlySelect" function adds a subquery to the SELECT query. It selects only the data returned by its function. You cannot use the other SELECT functions ("select" and "addSelect") when using "addOnlySelect".

You can use "addOnlySelect" function in subqueries

Using PDO Functions

You can use PDO functions as shown below. You can use all PDO functions provided by https://www.php.net/manual/en/class.pdo.php

To use the default database connection with a PDO object:

To use the selected database connection with a PDO object:

Using Different Databases

If a model uses a different database connection, you can configure it as follows:

JSON Response

When you want to return JSON data for your API, you can simply do the following:

You can customize the HTTP response code for a JSON response. The default HTTP response code is 200.

If you want to customize your JSON data, first create a resource collection class.

You must extend "JiJiHoHoCoCo\IchiORM\Resource\ResourceCollection" abstract class and declare "getSelectedResource()" function for your all resource collection classes.

You can create the resource class via terminal after creating "ichi" file as we mentioned in Create Model From Commandline

The default path for observer is "app/Resources". You can also change this in "ichi" file.

You can then return your custom JSON resource as shown below.

For an object array:

For a single object:

You can define relationships in your resource collection class (for both "refersTo" and "refersMany").

You can use another resource collection in your resource collection class, depending on whether the related data is a single object or an object array.

Caching

You can cache your query data with redis or memcached extensions in this library.

First, pass the Redis or Memcached object to the "setCacheObject" static function of "JiJiHoHoCoCo\IchiORM\Cache\CacheModel", as shown below.

With Redis

With Memcached

The connection method for Redis or Memcached may vary depending on your security requirements and available ports. The important point is that you must pass the Redis or Memcached object to the "setCacheObject" static function of "JiJiHoHoCoCo\IchiORM\Cache\CacheModel".

You can then use the cache functions to store and retrieve data.

In the "remember" function, you must specify the cache key, the query or data to store, and the expiration time in seconds. The expiration time is optional; if you omit it, the data is stored indefinitely. If the specified key does not exist in the cache server, the function stores the data and returns it. If the key already exists, the function retrieves the cached data.

The default expiration time is unlimited, so you should specify an expiration time when appropriate.

To delete a cached key, use:

You can save data directly to the cache:

To retrieve cached data:

You can retrieve the Redis object and use the functions provided by the Redis extension.

You can also retrieve the Memcached object and use the functions provided by Memcached.

Observers

To make observers firstly you need to create the observer class which implements "JiJiHoHoCoCo\IchiORM\Observer\ModelObserver" interface.

In this class, you must define the following functions:

  1. The "create" function is called after creating the blog model data.
  2. The "update" function is called after updating the blog model data.
  3. The "delete" function is called after deleting the blog model data.
  4. The "restore" function is called after restoring the soft-deleted blog model data.
  5. The "forceDelete" function is called after permanently deleting the blog model data.

You can create the observer via terminal after creating "ichi" file as we mentioned in Create Model From Commandline

The default directory for observers is "app/Observers". You can also change this in the "ichi" file.

After creating observer, you must do

You can also add many observers for one model

Observer functions are called sequentially.

If you want to observe a custom function:

In model

In observer

If you need to pass multiple parameters to an observer function:

In model

In observer

Supported PHP Versions

7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5


All versions of ichi-orm with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3|>=8.0
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 jijihohococo/ichi-orm contains the following files

Loading the files please wait ...