Skip to content

A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.

License

Notifications You must be signed in to change notification settings

scalajs-io/mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL API for Scala.js

mysql - A node.js driver for MySQL.

Description

A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.

Build Dependencies

Build/publish the SDK locally

$ sbt clean publish-local

Running the tests

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

Examples

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)
}

Artifacts and Resolvers

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") 

About

A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages