ScalikeJDBC is a tidy SQL-based DB access library for Scala that naturally wraps JDBC and provides easy-to-use APIs.
ScalikeJDBC is practical and production-ready. Use this library for your real projects.
Just add ScalikeJDBC, a JDBC driver, and an slf4j implementation to your sbt build settings:
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc" % "3.5.+",
"com.h2database" % "h2" % "1.4.+",
"ch.qos.logback" % "logback-classic" % "1.2.+"
)
If you're a Play2 user, take a look at play-support project, too:
https://github.com/scalikejdbc/scalikejdbc-play-support
After adding the above dependencies to your build.sbt
, run sbt console
and execute the following code:
import scalikejdbc._
// initialize JDBC driver & connection pool
Class.forName("org.h2.Driver")
ConnectionPool.singleton("jdbc:h2:mem:hello", "user", "pass")
// ad-hoc session provider on the REPL
implicit val session: DBSession = AutoSession
// table creation, you can run DDL by using #execute as same as JDBC
sql"""
create table members (
id serial not null primary key,
name varchar(64),
created_at timestamp not null
)
""".execute.apply()
// insert initial data
Seq("Alice", "Bob", "Chris") foreach { name =>
sql"insert into members (name, created_at) values (${name}, current_timestamp)".update.apply()
}
// for now, retrieves all data as Map value
val entities: List[Map[String, Any]] = sql"select * from members".map(_.toMap).list.apply()
// defines entity object and extractor
import java.time._
case class Member(id: Long, name: Option[String], createdAt: ZonedDateTime)
object Member extends SQLSyntaxSupport[Member] {
override val tableName = "members"
def apply(rs: WrappedResultSet) = new Member(
rs.long("id"), rs.stringOpt("name"), rs.zonedDateTime("created_at"))
}
// find all members
val members: List[Member] = sql"select * from members".map(rs => Member(rs)).list.apply()
// use paste mode (:paste) on the Scala REPL
val m = Member.syntax("m")
val name = "Alice"
val alice: Option[Member] = withSQL {
select.from(Member as m).where.eq(m.name, name)
}.map(rs => Member(rs)).single.apply()
How did it go? If you'd like to know more details or see more practical examples, see the full documentation at:
Published source code and binary files have the following copyright:
Copyright scalikejdbc.org
Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.html
ScalikeJdbc的增删改查操作 运用该技术,在scala小项目里面可以很简单的往mysql内插入数据。 1、导入依赖 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <dependency
Just write SQL and get things done! ScalikeJDBC is a tidy SQL-based DB access library for Scala that naturally wraps JDBC and provides easy-to-use APIs. ScalikeJDBC is practical and production-ready.
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/caiyefly/article/details/78045526 ScalikeJDBC基于SQL的简介DB访问 1. 什么是ScalikeJDBC ScalikeJDBC是一款给Scala开发者使用的简洁DB访问类库,它是基于SQL的,使用者只需要关注SQL逻辑的编写,所有的数据库操作都交
一、构建maven项目,添加pom.xml依赖 2.11.8 3.3.2 org.scalikejdbc scalikejdbc_2.11 ${scalikejdbc.version} org.scalikejdbc scalikejdbc-config_2.11 ${scalikejdbc.version} 二、resource文件下创建application.conf文件,并配置以下内容 #
ScalikeJDBC 基于 SQL 的简介 DB 访问 1. 什么是 ScalikeJDBC ScalikeJDBC 是一款给 Scala 开发者使用的简洁 DB 访问类库,它是基于 SQL 的,使用者 只需要关注 SQL 逻辑的编写,所有的数据库操作都交给 ScalikeJDBC。这个类库内置包含了 JDBC API,并且给用户提供了简单易用并且非常灵活的 API。并且,QueryDSL(
第一步,导包 pom.xml <dependency> <groupId>org.scalikejdbc</groupId> <artifactId>scalikejdbc_2.11</artifactId> <version>2.5.0</version> </dependency>
在scala中有一个基于SQL的数据库访问库就是scalikeJDBC,官网地址如下: http://scalikejdbc.org/ 1.将pom依赖加入pom.xml文件 <!-- mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connec
初识Scalikejdbc 官网 ScalikeJDBC 是一款给 Scala 开发者使用的简洁 DB 访问类库,它是基于 SQL 的,使用者 只需要关注 SQL 逻辑的编写,所有的数据库操作都交给 ScalikeJDBC。这个类库内置包含了 JDBC API,并且给用户提供了简单易用并且非常灵活的 API。并且,QueryDSL(通用查询查询 框架)使你的代码类型安全的并且可重复使用。我们可以在
问题内容: 我在玩图书馆。我想从PostgreSQL数据库中检索数据。我得到的错误对我来说很奇怪。即使我手动配置CP: 我仍然看到错误。这是我的DAO: 该应用程序: 我的档案 错误: 我错过了什么? 问题答案: 要加载,应提前调用scalikejdbc-config 。 http://scalikejdbc.org/documentation/configuration.html#scalike
为了避免DRY,我试图创建一个sql INSERT语句,其中包含变量列名和通过ScalikeJDBC的sql内插填充这些列的数据: 当我把这个叫做: sql语句是:INSERT INTO?(?,?)值(?,?) 参数为:List(My_Table,key,email,42,user@email.com) 您的SQL语法中有一个错误;检查与您的MySQL server版本对应的手册,查找使用“my_