Skip to content

Commit

Permalink
SQLite support effort
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Apr 11, 2024
1 parent 544f55e commit 50a982e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion sqlite/src/main/scala/lightdb/sqlite/SQLiteSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,38 @@ import lightdb.{Document, Id}
import lightdb.index.{IndexSupport, Indexer}
import lightdb.query.{PagedResults, Query, SearchContext}

import java.nio.file.{Files, Path}
import java.sql.{Connection, DriverManager}

trait SQLiteSupport[D <: Document[D]] extends IndexSupport[D] {
private lazy val path: Path = db.directory.resolve("sqlite.db")
// TODO: Should each collection have a connection?
private lazy val connection: Connection = {
val c = DriverManager.getConnection(s"jdbc:sqlite:${path.toFile.getCanonicalPath}")
c.setAutoCommit(false)
c
}

override lazy val index: SQLiteIndexer[D] = SQLiteIndexer(this)

override def doSearch(query: Query[D],
context: SearchContext[D],
offset: Int,
after: Option[PagedResults[D]]): IO[PagedResults[D]] = ???

override def dispose(): IO[Unit] = super.dispose().map { _ =>
connection.close()
}
}

case class SQLiteIndexer[D <: Document[D]](indexSupport: IndexSupport[D]) extends Indexer[D] {
case class SQLiteIndexer[D <: Document[D]](indexSupport: SQLiteSupport[D]) extends Indexer[D] {
override def withSearchContext[Return](f: SearchContext[D] => IO[Return]): IO[Return] = ???

override def count(): IO[Int] = ???

override private[lightdb] def delete(id: Id[D]): IO[Unit] = ???

override def commit(): IO[Unit] = ???


}

0 comments on commit 50a982e

Please sign in to comment.