標籤:
建立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就像是個二維表了
mysql asyn 實戰