Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Slick and SQLite

I'm trying to create a database using Scala and SQLite. I'm using Slick as the library for the SQLite. I've been googling around for hours and still can't figure out how to get this working. I have eclipse project with Slick installed. I'm trying to instanciate the database with

val db = Database.forUrl("url",driver = "org.SQLite.Driver")

I have no idea what to put in the url. I'm not very sure about the driver part either. Should I use that one or does "scala.slick.driver.SQLiteDriver" work too? Or does it even matter?

I'm really confused about all this.Any help is appreciated

Thanks!

like image 432
Ou Tsei Avatar asked Dec 23 '14 17:12

Ou Tsei


1 Answers

JDBC relies on drivers that implement the JDBC API, and provide access to the low-level functionality of working with particular databases.

URLs are how you tell a JDBC driver which database you want to connect to. The first part of the URL is always jdbc:<driverId>:, where driverId is the specific name that the driver expects to see (e.g. postgresql, mysql or, in your case sqlite.) The format of the URL after the driver ID is specific to the particular driver implementation. With mysql and postgres, where you typically connect over TCP to the database server, you'll see a format like this:

jdbc:mysql://dbserver:dbport/databaseName

jdbc:postgresql://dbserver:dbport/databaseName

But, since SQLite is an in-process, local database, the part of the URL after the driver ID is just a filesystem path, like so:

jdbc:sqlite:/home/me/my-db-file.sqlite
like image 120
Alex Cruise Avatar answered Nov 14 '22 00:11

Alex Cruise