mysql asyn 实战

mysql asyn 实战,第1张

mysql asyn 实战

创建configuration时,发现URLParser找不到,于是只能使用配置文件来,当然使用配置文件比使用URL初始化还要直观些

def configurationWithPassword = new Configuration(
host = "localhost",
port = 3306,
username = "root",
password = Some("123"),
database = Some("test")
)

Configuration文件本身是case class,它的code是

case class Configuration(username: String,
host: String = "localhost",
port: Int = 5432,
password: Option[String] = None,
database: Option[String] = None,
charset: Charset = Configuration.DefaultCharset,
maximumMessageSize: Int = 16777216,
allocator: AbstractByteBufAllocator = PooledByteBufAllocator.DEFAULT,
connectTimeout: Duration = 5.seconds,
testTimeout: Duration = 5.seconds
)

这让我想到了slick,slick我连配置文件都搞不出来。


总觉得slick的设计有些反人类。


对于单连接

  def sinConnection: MySQLConnection = {
val configuration: Configuration = configurationWithPassword
new MySQLConnection(configuration)
}

对于线程池连接

def poolConnection: ConnectionPool[MySQLConnection] = {
val configuration: Configuration = configurationPool
val factory = new MySQLConnectionFactory(configuration)
val pool = new ConnectionPool[MySQLConnection](factory, PoolConfiguration.Default)
pool
}

ResultSet并不是java.sql.resultSet而是作者自己创建的新类型

trait ResultSet extends IndexSeq[RowData]

而rowData则表示一行数据,也是一个顺序

trait RowData extends IndexedSeq[Any]

这样,ResultSet就像是个二维表了

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/587575.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存