bootpress / sqlite
扩展BootPress数据库组件,以便随意创建和更新表和索引,并简化FTS全文搜索。
v1.0
2016-09-26 05:43 UTC
Requires
- php: >=5.4
- ext-sqlite3: *
- bootpress/database: ^1.0
Requires (Dev)
- bootpress/page: ^1.0
- friendsofphp/php-cs-fixer: ^1.0
- phpunit/phpunit: ^4.0
- squizlabs/php_codesniffer: ^2.5
- symfony/yaml: ^2.3||^3.0
This package is not auto-updated.
Last update: 2024-09-14 19:14:48 UTC
README
扩展BootPress\Database\Component,以便轻松随意创建和更新SQLite数据库表和索引。它覆盖了数据库组件的底层PDO包装器,以使用PHP SQLite3类。主要原因是为了在调用$db->connection()->close()
时能够释放文件。唯一的副作用是你不能获取'obj'或'named'行。除此之外,我们还在这里添加了更多功能。它还方便了FTS全文搜索。
安装
将以下内容添加到您的composer.json
文件中。
{ "require": { "bootpress/sqlite": "^1.0" } }
示例用法
<?php use BootPress\SQLite\Component as Sqlite; $db = new Sqlite; // An in-memory database if ($db->created) { $db->settings('version', '1.0'); $db->create('employees', array( 'id' => 'INTEGER PRIMARY KEY', 'name' => 'TEXT COLLATE NOCASE', 'position' => 'TEXT NOT NULL DEFAULT ""', ), array('unique'=>'position')); // Wait, I just changed my mind: $db->create('employees', array( 'id' => 'INTEGER PRIMARY KEY', 'name' => 'TEXT UNIQUE COLLATE NOCASE', 'title' => 'TEXT DEFAULT ""', ), 'title', array( 'position' => 'title', )); $db->fts->create('results', 'search'); // You can insert, update, and query an FTS table the same as any other. if ($stmt = $db->insert('results', array('docid', 'search'))) { $db->insert($stmt, array(100, 'Fisherman never die, they just get reel tired.')); $db->insert($stmt, array(101, 'If wishes were fishes, we\'d have a fish fry.')); $db->insert($stmt, array(102, 'Women want me, fish fear me.')); $db->insert($stmt, array(103, 'Good things come to those who bait.')); $db->insert($stmt, array(104, 'A reel expert can tackle anything.')); } } echo $db->settings('version'); // 1.0 echo $db->fts->count('results', 'fish')); // 2 print_r($db->fts->search('results', 'fish')); /* array( array( 'docid' => 101, 'snippet' => "If wishes were <b>fishes</b>, we'd have a <b>fish</b> fry.", 'offsets' => '0 0 15 6 0 0 35 4', 'rank' => 1.333, ), array( 'docid' => 102, 'snippet' => 'Women want me, <b>fish</b> fear me.', 'offsets' => '0 0 15 4', 'rank' => .666, ), ) */ echo implode(', ', $db->fts->words('results', 'fish', 101)); // fishes, fish
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。