Download the PHP package sw-serv/relational-db without Composer
On this page you can find all versions of the php package sw-serv/relational-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sw-serv/relational-db
More information about sw-serv/relational-db
Files in sw-serv/relational-db
Package relational-db
Short Description This package provide advanced features to manipulate openswoole tables
License GPL-3.0-only
Informations about the package relational-db
This package provide advanced features to manipulate OpenSwoole\Table.
The heavy advantages of OpenSwoole\Table is heavy speed access : you can read about 2 million records in one second, and it is shared between processes.
This package intend to allow you to easy manage OpenSwoole\Table.
Registries
Table registry
Table registry is your entry point to small-swoole-db
You can :
- create a table in memory and register it
- get a table already registered
- destroy a table in memory
- persist a table to :
- Json file
- Redis
- Mysql
- Load a table previously persisted
Create a table
To create a table, use registry method :
- The first param is the table name in registry. Use it to recall table from other parts of code.
- The second param is the max number of rows in the table
Once the table is created in registry, you can add columns :
Only these type are accepted :
- ColumnType::string
- ColumnType::float
- ColumnType::int
Note the size param is required, except for flot type
Now we have added the columns, we can create in memory :
The table is now ready to use as a OpenSwoole\Table object :
Foreign key
You can link two tables throw foreign key.
See OpenSwoole documentation for Table
Destroy a table
Once you don't need anymore table, you can destroy it to free all associated memory.
This will destroy table and remove it from registry
Persistence
When you need persistence for table, you can store table to a json file.
Soon, I will develop redis and mysql persistence but for now, use default persistence :
This will store table definition in a json file stored in /var/lib/small-swoole-db/data/testTable.json
To reload table from disk (at server restart for example) :
This will restore table in registry and memory with all data from last persist.
ParamRegistry
If you want, you can use ParamRegistry to change :
-
location of /var/lib direcoty :
- data dir name :
In this example, the testTable table will be stored in :
Selector
You can use selector to build complex requests.
Basically, you can select all records :
You can use where to add conditions :
You can also join result throw foreign keys :
And select any of fields (note that you can change record and persist easily) :
Testing
You must have docker installed to run tests.
To build unit-test container and run test suite, use command :
Once the container is build, you can quickly run test using :