mysql - A node.js driver for MySQL.
A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.
$ sbt clean publish-local
Before running the tests the first time, you must ensure the npm packages are installed:
$ npm install
Then you can run the tests:
$ sbt test
import io.scalajs.nodejs._
import io.scalajs.npm.mysql._
import scala.concurrent.duration._
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
// establish a connection
val conn = MySQL.createConnection(
new ConnectionOptions(
host = "localhost",
database = "tracking_data",
user = "root",
password = ""
))
// close connection after 60 seconds
setTimeout(() => {
console.log("Closing connection...")
conn.destroy()
}, 60.seconds)
// retrieve some records
val results = conn.query("SELECT * FROM activity LIMIT 1")
results.onFields(fields => console.log("fields => %j", fields.head))
results.onResult(console.log("row => %j", _))
// retrieve some records via the `for` comprehension
for {
(rows, fields) <- conn.queryFuture[Activity]("SELECT * FROM activity LIMIT 1")
} {
console.log("fields => %j", fields.head)
console.log("rows => %j", rows.head)
}
To add the MySQL
binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "mysql" % "0.5.0"
Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")