Scala database access toolslick

Source: Internet
Author: User
Slick is the Scala database access library launched by TypeSafe. Developers can use the Scala language to write data queries, rather than SQL. Example code: packagecom. testimportscala. slick. driver. MySQLDriver. simple. _ importcom. mysql. jdbc. jdbc2.optional. MysqlDataSourceimportscala

Slick is the Scala database access library launched by TypeSafe. Developers can use the Scala language to write data queries instead of SQL statements. Example code: package com. testimport scala. slick. driver. mySQLDriver. simple. _ import com. mysql. jdbc. jdbc2.optional. mysqlDataSourceimport scala

Slick is the Scala database access library launched by TypeSafe. Developers can use the Scala language style to write data queries, rather than SQL. Example code:

Package com. testimport scala. slick. driver. mySQLDriver. simple. _ import com. mysql. jdbc. jdbc2.optional. mysqlDataSourceimport scala. slick. session. databaseimport scala. slick. session. sessionobject Supplier extends Table [(String, Int)] ("test") {def name = column [String] ("name ") def age = column [Int] ("age") def * = name ~ Agedef main (args: Array [String]) {val session = Sandbox. databaseval query = tableToQuery (Supplier) // query. selectStatement // query. foreach (println (_) (session) // update // val uq = Supplier. filter (p => p. name = "ricki "). map (_. age) /// uq. updateStatement // uq. update (24) (session) // insert // val in = Supplier. name ~ Supplier. age /// in. insertStatement // in. insert ("cherry", 1) (session) // Delete val dq = Supplier. filter (_. name = "cherry") dq. deleteStatementdq. delete (session) session. close} object Sandbox {def database: Session = {val dataSource = new MysqlDataSource () dataSource. setUser ("root") dataSource. setPassword ("root") dataSource. setDatabaseName ("test") val dataBase = Database. forDataSource (dataSource) dataBase. createSession }}

For more information, see the official website: http://slick.typesafe.com/docs/

Official third-party Tutorial: http://mackler.org/LearningSlick/#id11540725

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.