package Ġorg . ab ond ar . experimental . phone . server . conf Ċ Ċ import Ġcom . types afe . config . Config Factory Ċ import Ġcom . zaxxer . hikari . HikariConfig Ċ import Ġcom . zaxxer . hikari . Hikari DataSource Ċ import Ġio . ktor . application . Application Ċ import Ġio . ktor . config .* Ċ import Ġio . ktor . util . K tor Experimental API Ċ import Ġorg . ab ond ar . experimental . phone . server . model . Contacts Ċ import Ġorg . ab ond ar . experimental . phone . server . model . Users Ċ import Ġorg . jetbrains . ex posed . sql . Database Ċ import Ġorg . jetbrains . ex posed . sql . Schema Utils Ċ import Ġorg . jetbrains . ex posed . sql . transactions . transaction Ċ import Ġorg . slf 4 j . LoggerFactory ĊĊĊ Ċ @ K tor Experimental API Ċ fun Ġinit DB () Ġ{ ĊĠĠĠ Ġval Ġconf Ġ= ĠHo con Application Config ( Config Factory . load ()) ĊĊĠĠĠ Ġval ĠdataSource Ġ= Ġh ik ary ( conf ) ĊĠĠĠ ĠDatabase . connect ( dataSource ) ĊĠĠĠ Ġcreate Tables () ĊĠĠĠ ĠLoggerFactory . getLogger ( Application :: class . simple Name ). info (" Initialized ĠDatabase ") Ċ } ĊĊ Ċ fun Ġinit Test DB () Ġ{ ĊĊĠĠĠ ĠDatabase . connect (" jdbc : h 2 : mem : test ; DB _ CLOSE _ DELAY =- 1 ", Ġ" org . h 2 . Driver ") ĊĠĠĠ Ġcreate Tables () ĊĠĠĠ ĠLoggerFactory . getLogger ( Application :: class . simple Name ). info (" Initialized Ġtest ĠDatabase ") Ċ } ĊĊ Ċ private Ġfun Ġh ik ary ( conf Ġ: ĠHo con Application Config ) Ġ: ĠH ikari DataSource { ĊĠĠĠ Ġval Ġdb Conf Ġ= ĠH ikariConfig () ĊĊĠĠĠ Ġdb Conf . driver ClassName Ġ= Ġconf . property (" dataSource . className "). getString () ĊĠĠĠ Ġdb Conf . username = conf . property (" dataSource . user "). getString () ĊĠĠĠ Ġdb Conf . password = conf . property (" dataSource . password "). getString () ĊĠĠĠ Ġdb Conf . jdbc Url = conf . property (" dataSource . url "). getString () ĊĠĠĠ Ġdb Conf . maximum PoolSize = conf . property (" dataSource . max PoolSize "). getString (). toInt () ĊĠĠĠ Ġdb Conf . is Auto Commit = conf . property (" dataSource . auto Commit "). getString (). to Boolean () ĊĠĠĠ Ġdb Conf . transaction Isolation = conf . property (" dataSource . transaction Isolation "). getString () ĊĊĊĠĠĠ Ġdb Conf . validate () ĊĊĠĠĠ Ġreturn ĠH ikari DataSource ( db Conf ) Ċ } Ċ Ċ private Ġfun Ġcreate Tables () Ġ= Ġtransaction Ġ{ ĊĠĠĠ ĠSchema Utils . create ( Users , Contacts ) Ċ } Ċ