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 許可。