queryflatfile
3.1.0

queryflatfile是一个用 PHP 编写的平面文件数据库库。默认以JSON格式存储数据,还支持txt 、 msgPack 和 igbinary 格式。使用类似于 SQL 语法的 QueryBuilder 操作数据。
| PHP版本 | queryflatfile 3.1.x |
|---|---|
| <= 7.1 | ✗ 不支持 |
| 7.2 / 7.3 / 7.4 | ✓ 支持 |
| 8.0/8.1/8.2 | ✓ 支持 |
txt用于使用 PHP 序列化记录数据,json用于以 JSON 格式记录数据,所需的最小内存量取决于您要处理的数据量和操作类型。
在存储数据的目录中写入和读取文件的权限。
要通过 Composer 安装queryflatfile ,您必须拥有安装程序或二进制文件 Composer
转到您的项目目录,打开命令提示符并运行以下命令:
composer require soosyze/ queryflatfile --no-dev或者,如果您使用二进制文件,
php composer.phar require soosyze/ queryflatfile --no-dev require __DIR__ . ' /vendor/autoload.php ' ;
use Soosyze queryflatfile Schema ;
use Soosyze queryflatfile Request ;
use Soosyze queryflatfile TableBuilder ;
use Soosyze queryflatfile Driver Json ;
$ sch = new Schema ( __DIR__ . ' data ' , ' schema ' , new Json ());
$ req = new Request ( $ sch );
$ sch -> createTableIfNotExists ( ' user ' , function ( TableBuilder $ table ): void {
$ table -> increments ( ' id ' )
$ table -> string ( ' name ' )
$ table -> string ( ' firstname ' )-> nullable ();
});
$ req -> insertInto ( ' user ' , [ ' name ' , ' firstname ' ])
-> values ([ ' NOEL ' , ' Mathieu ' ])
-> values ([ ' DUPOND ' , ' Jean ' ])
-> values ([ ' MARTIN ' , null ])
-> execute ();
$ data = $ req -> select ( ' id ' , ' name ' )
-> from ( ' user ' )
-> where ( ' firstname ' , ' = ' , ' Jean ' )
-> fetch ();
print_r ( $ data );
$ sch -> dropTableIfExists ( ' user ' );上面的例子将输出:
Array
(
[id] => 2
[name] => DUPOND
)
模式
dropSchema() ,getIncrement( string $tableName ) ,getSchema() ,getTableSchema( string $tableName ) ,hasColumn( string $tableName, $columnName ) ,hasTable( string $tableName ) ,setConfig( string $host, string $name = 'schema', DriverInterface $driver = null ) 。处理表
alterTable( string $tableName, callable $callback ) ,createTable( string $tableName, callable $callback = null ) ,createTableIfNotExists( string $tableName, callable $callback = null ) :boolean( string $name ) ,char( string $name, $length = 1) ,date( string $name ) ,dateTime( string $name ) ,float( string $name ) ,increments( string $name ) ,integer( string $name ) ,string( string $name, $length = 255) ,text( string $name ) 。dropTable( string $tableName ) ,dropTableIfExists( string $tableName ) ,truncateTable( string $tableName ) 。选型要求
select( string ...$columnNames ) ,from( string $tableName ) ,leftJoin( string $tableName, Closure|string $column, string $condition = '', string $value = '' ) ,rightJoin( string $tableName, Closure|string $column, string $condition = '', string $value = '' ) ,union( RequestInterface $union ) ,unionAll( RequestInterface $union ) ,orderBy( string $columnName, int $order = SORT_DESC|SORT_ASC ) ,limit( int $limit, int $offset = 0 ) 。请求执行
insertInto( string $tableName, array $columnNames ) ,values( array $rowValues ) ,update( string $tableName, array $row ) ,delete() ,execute()执行数据的插入、修改和删除。查询结果
fetch(): array返回查询的第一个结果,fetchAll(): array返回所有查询结果,lists( string $columnName, string $key = null ): array返回传入参数的列的列表。在哪里
where( string $columnName, string $condition, null|scalar $value ) ,orWhere( string $columnName, string $condition, null|scalar $value ) ,notWhere( string $columnName, string $condition, null|scalar $value ) ,orNotWhere( string $columnName, string $condition, null|scalar $value ) 。支持的条件(===、==、!=、<>、<、<=、>、>=、like、ilike、not like、not ilike)
在哪里
whereGroup( Closure $columnName ) ,orWhereGroup( Closure $columnName ) ,notWhereGroup( Closure $columnName ) ,orNotWhereGroup( Closure $columnName ) 。之间在哪里
between( string $columnName, $min, $max ) ,orBetween( string $columnName, $min, $max ) ,notBetween( string $columnName, $min, $max ) ,orNotBetween( string $columnName, $min, $max ) 。在哪里
in( string $columnName, array $values ) ,orIn( string $columnName, array $values ) ,notIn( string $columnName, array $values ) ,orNotIn( string $columnName, array $values ) 。哪里为空
isNull( string $columnName ) ,orIsNull( string $columnName ) ,isNotNull( string $columnName ) ,orIsNotNull( string $columnName ) 。正则表达式在哪里
regex( string $columnName, string $pattern ) ,orRegex( string $columnName, string $pattern ) ,notRegex( string $columnName, string $pattern ) ,orNotRegex( string $columnName, string $pattern ) 。 有关使用示例,请参阅用户文档。
该项目已获得 MIT 许可。