From a33fedef5cb64b7caf12d17ed5a916151cf1bd00 Mon Sep 17 00:00:00 2001 From: Matt Hicks Date: Mon, 2 Dec 2024 11:37:51 -0600 Subject: [PATCH] Fixes to DatabaseRestore and cleanup of SQLiteStore --- build.sbt | 4 +-- .../lightdb/backup/DatabaseRestore.scala | 7 ++++- .../main/scala/lightdb/sql/SQLiteStore.scala | 30 +++++++------------ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/build.sbt b/build.sbt index 855d932..4545660 100644 --- a/build.sbt +++ b/build.sbt @@ -15,7 +15,7 @@ val developerURL: String = "https://matthicks.com" name := projectName ThisBuild / organization := org -ThisBuild / version := "0.17.0" +ThisBuild / version := "1.0.0-SNAPSHOT" ThisBuild / scalaVersion := scala213 ThisBuild / crossScalaVersions := allScalaVersions ThisBuild / scalacOptions ++= Seq("-unchecked", "-deprecation") @@ -298,7 +298,7 @@ lazy val docs = project .enablePlugins(MdocPlugin) .settings( mdocVariables := Map( - "VERSION" -> version.value + "VERSION" -> version.value ), mdocOut := file(".") ) \ No newline at end of file diff --git a/core/src/main/scala/lightdb/backup/DatabaseRestore.scala b/core/src/main/scala/lightdb/backup/DatabaseRestore.scala index bde7d24..23d4f19 100644 --- a/core/src/main/scala/lightdb/backup/DatabaseRestore.scala +++ b/core/src/main/scala/lightdb/backup/DatabaseRestore.scala @@ -65,11 +65,16 @@ object DatabaseRestore { f(collection) match { case Some(source) => try { + scribe.info(s"Restoring ${collection.name}...") if (truncate) collection.t.truncate() val iterator = source .getLines() .map(s => JsonParser(s)) - collection.t.json.insert(iterator) + val count = collection.t.json.insert(iterator) + scribe.info(s"Re-Indexing ${collection.name}...") + collection.reIndex() + scribe.info(s"Restored $count documents to ${collection.name}") + count } finally { source.close() } diff --git a/sqlite/src/main/scala/lightdb/sql/SQLiteStore.scala b/sqlite/src/main/scala/lightdb/sql/SQLiteStore.scala index f75eb9d..b98c694 100644 --- a/sqlite/src/main/scala/lightdb/sql/SQLiteStore.scala +++ b/sqlite/src/main/scala/lightdb/sql/SQLiteStore.scala @@ -100,27 +100,17 @@ class SQLiteStore[Doc <: Document[Doc], Model <: DocumentModel[Doc]](val connect object SQLiteStore extends StoreManager { def singleConnectionManager(file: Option[Path]): ConnectionManager = { - val connection: Connection = { - val path = file match { - case Some(f) => - val file = f.toFile - Option(file.getParentFile).foreach(_.mkdirs()) - file.getCanonicalPath - case None => ":memory:" - } - - val config = new SQLiteConfig - config.enableLoadExtension(true) - val uri = s"jdbc:sqlite:$path" - try { - val c = config.createConnection(uri) - c.setAutoCommit(false) - c - } catch { - case t: Throwable => throw new RuntimeException(s"Error establishing SQLite connection to $uri", t) - } + val path = file match { + case Some(f) => + val file = f.toFile + Option(file.getParentFile).foreach(_.mkdirs()) + file.getCanonicalPath + case None => ":memory:" } - SingleConnectionManager(connection) + + SingleConnectionManager(SQLConfig( + jdbcUrl = s"jdbc:sqlite:$path" + )) } def apply[Doc <: Document[Doc], Model <: DocumentModel[Doc]](file: Option[Path], storeMode: StoreMode): SQLiteStore[Doc, Model] = {