| @@ 23-32 (lines=10) @@ | ||
| 20 | * @throws \RuntimeException if database already exists. |
|
| 21 | * @return IndexDB |
|
| 22 | */ |
|
| 23 | public function build_index_db($path) { |
|
| 24 | if (file_exists($path)) { |
|
| 25 | throw new \RuntimeException("File at '$path' already exists, can't build database."); |
|
| 26 | } |
|
| 27 | $connection = DB::sqlite_connection($path); |
|
| 28 | $db = new IndexDB($connection); |
|
| 29 | $db->init_sqlite_regexp(); |
|
| 30 | $db->init_database_schema(); |
|
| 31 | return $db; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Check if an index database exists. |
|
| @@ 51-59 (lines=9) @@ | ||
| 48 | * @throws \RuntimeException if file does not exist |
|
| 49 | * @return IndexDB |
|
| 50 | */ |
|
| 51 | public function load_index_db($path) { |
|
| 52 | if (!$this->index_db_exists($path)) { |
|
| 53 | throw new \RuntimeException("There is no index database at '$path'"); |
|
| 54 | } |
|
| 55 | $connection = DB::sqlite_connection($path); |
|
| 56 | $db = new IndexDB($connection); |
|
| 57 | $db->init_sqlite_regexp(); |
|
| 58 | return $db; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||