Download the PHP package peroks/model-store without Composer

On this page you can find all versions of the php package peroks/model-store. 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 model-store

Model Store: Permanent data store for models.

Reason why

The purpose of this package is to store models permanently. Currently, JSON files and MySql databases (mysqli and pdo-mysql) are supported.

The Model Store is an abstraction layer on top of the permanent store. It automatically creates JSON files or database schemas for you based on your models.

The Model Store provides a simple interface for reading models from and writing models to the permanents store.

How to use

The Store interface

You can of course access a database directly, but the recommended way it to create a Store instance and use the StoreInterface.

Connecting to a model store

In order to connect to a model store, you must create a new model store instance. Currently, these model stores are supported:

The JsonStore classes stores models in MySQL json columns with additional columns for indices and constraints.

You can also create your own implementation of the StoreInterface.

File store

Storing your models in a JSON file is only recommended for very small data stores, no more than a few MBs. It's intended for use in development and rapid prototyping, but not in production. For each PHP request the complete JSON file is loaded into memory, and it will consume more and more ram and cpu as the file grows.

To connect to a JSON file store, just provide the full path and file name to the JSON file which contains your models. If the file does not exist, it will be created.

PDO MySql store

To connect to a PDO MySql store, just provide the connection info for the MySQL database.

All connection properties below are required, except for port and socket, which are mutually exclusive. If the host is localhost, a socket is expected. The connection info can be an array or an object.

Alternatively, you can use the PdoJsonStore class, which stores the models in MySql json columns. Additional columns are only created for primary, index and constraint properties.

Native MySql (mysqli) store

You can also connect to a MySql database using the native mysqli driver if you prefer. Just replace the store class PdoStore with MysqlStore.

Alternatively, you can use the MysqlJsonStore class, which stores the models in MySql json columns. Additional columns are only created for primary, index and constraint properties.

Creating and Updating database schemas

Before you can start using a database store, you need to build the database schema based on your models. Fortunately, you don't need to do this manually. To create (and update) your database schema, call the build() method with an array of the model class names that you want to store. This will also create a new database if it doesn't already exist.

You should only call the build() method when you create a new model store or when your models have changed. Do not call build() every time you connect to the store. You can use info( 'ready' ) to check if the db is ready for use or not.

If a model contains sub-models, database tables are automatically created for the sub-models. You do not need to include sub-models in the build() method. So, if you have a hierarchy of models, you only need to provide your top-level models.

Caching

You can cache query results in memory with the special Cache store. The constructor takes another store instance as the only argument. Calls to has(), get(), list() and filter() return cached results when available. The cache is cleared every time set(), delete() or build() are called.

Examples

The below examples assume that a model store instance has already been created, i.e. like this

All methods accept the model class name as the first argument. The only exception is set, since the class name can be derived from the model instance.

Check if a model exists in the store

Get a single model by id

Get an array of models by their ids

If no ids are provided, all models of the given class are returned.

Get models by their property values

The filter method returns all models of the given class name matching pairs of property ids and their values, i.e.

If no property filter is provided, all models of the given class are returned (same as list()).

Add or update a model in the store

Delete a model from the store

Installing

You need composer to download and install this package. Just run composer require peroks/model-store in your project.


All versions of model-store with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
peroks/model Version ^3.0.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 peroks/model-store contains the following files

Loading the files please wait ...