@@ -8,7 +8,7 @@ import kotlinx.uuid.*
8
8
import libpq.*
9
9
import kotlin.time.*
10
10
11
- class PostgresNativeDriver (private var conn : CPointer <PGconn >) : SqlDriver {
11
+ public class PostgresNativeDriver (private var conn : CPointer <PGconn >) : SqlDriver {
12
12
private var transaction: Transacter .Transaction ? = null
13
13
14
14
init {
@@ -35,7 +35,7 @@ class PostgresNativeDriver(private var conn: CPointer<PGconn>) : SqlDriver {
35
35
36
36
}
37
37
38
- override fun currentTransaction () = transaction
38
+ override fun currentTransaction (): Transacter . Transaction ? = transaction
39
39
40
40
override fun execute (
41
41
identifier : Int? ,
@@ -200,7 +200,7 @@ class PostgresNativeDriver(private var conn: CPointer<PGconn>) : SqlDriver {
200
200
}
201
201
}
202
202
203
- fun copy (stdin : String ): Long {
203
+ public fun copy (stdin : String ): Long {
204
204
val status = PQputCopyData (conn, stdin, stdin.encodeToByteArray().size)
205
205
check(status == 1 ) {
206
206
conn.error()
@@ -241,7 +241,7 @@ private fun CPointer<PGresult>?.check(conn: CPointer<PGconn>): CPointer<PGresult
241
241
/* *
242
242
* Must be inside a transaction!
243
243
*/
244
- class PostgresCursor (
244
+ public class PostgresCursor (
245
245
private var result : CPointer <PGresult >,
246
246
private val name : String ,
247
247
private val conn : CPointer <PGconn >
@@ -252,7 +252,7 @@ class PostgresCursor(
252
252
conn.exec(" END" )
253
253
}
254
254
255
- override fun getBoolean (index : Int ) = getString(index)?.toBoolean()
255
+ override fun getBoolean (index : Int ): Boolean? = getString(index)?.toBoolean()
256
256
257
257
override fun getBytes (index : Int ): ByteArray? {
258
258
val isNull = PQgetisnull (result, tup_num = 0 , field_num = index) == 1
@@ -285,9 +285,9 @@ class PostgresCursor(
285
285
return array
286
286
}
287
287
288
- override fun getDouble (index : Int ) = getString(index)?.toDouble()
288
+ override fun getDouble (index : Int ): Double? = getString(index)?.toDouble()
289
289
290
- override fun getLong (index : Int ) = getString(index)?.toLong()
290
+ override fun getLong (index : Int ): Long? = getString(index)?.toLong()
291
291
292
292
override fun getString (index : Int ): String? {
293
293
val isNull = PQgetisnull (result, tup_num = 0 , field_num = index) == 1
@@ -299,24 +299,24 @@ class PostgresCursor(
299
299
}
300
300
}
301
301
302
- fun getDate (index : Int ): LocalDate ? = getString(index)?.toLocalDate()
303
- fun getTime (index : Int ): LocalTime ? = getString(index)?.toLocalTime()
304
- fun getLocalTimestamp (index : Int ): LocalDateTime ? = getString(index)?.replace(" " , " T" )?.toLocalDateTime()
305
- fun getTimestamp (index : Int ): Instant ? = getString(index)?.let {
302
+ public fun getDate (index : Int ): LocalDate ? = getString(index)?.toLocalDate()
303
+ public fun getTime (index : Int ): LocalTime ? = getString(index)?.toLocalTime()
304
+ public fun getLocalTimestamp (index : Int ): LocalDateTime ? = getString(index)?.replace(" " , " T" )?.toLocalDateTime()
305
+ public fun getTimestamp (index : Int ): Instant ? = getString(index)?.let {
306
306
Instant .parse(it.replace(" " , " T" ))
307
307
}
308
308
309
- fun getInterval (index : Int ): Duration ? = getString(index)?.let { Duration .parseIsoString(it) }
310
- fun getUUID (index : Int ): UUID ? = getString(index)?.toUUID()
309
+ public fun getInterval (index : Int ): Duration ? = getString(index)?.let { Duration .parseIsoString(it) }
310
+ public fun getUUID (index : Int ): UUID ? = getString(index)?.toUUID()
311
311
312
312
override fun next (): Boolean {
313
313
result = PQexec (conn, " FETCH NEXT IN $name " ).check(conn)
314
314
return PQcmdTuples (result)!! .toKString().toInt() == 1
315
315
}
316
316
}
317
317
318
- class PostgresPreparedStatement (private val parameters : Int ) : SqlPreparedStatement {
319
- fun values (scope : AutofreeScope ): CValuesRef <CPointerVar <ByteVar >> = createValues(parameters) {
318
+ public class PostgresPreparedStatement (private val parameters : Int ) : SqlPreparedStatement {
319
+ internal fun values (scope : AutofreeScope ): CValuesRef <CPointerVar <ByteVar >> = createValues(parameters) {
320
320
value = when (val value = _values [it]) {
321
321
null -> null
322
322
is Data .Bytes -> value.bytes.refTo(0 ).getPointer(scope)
@@ -330,9 +330,9 @@ class PostgresPreparedStatement(private val parameters: Int) : SqlPreparedStatem
330
330
}
331
331
332
332
private val _values = arrayOfNulls<Data >(parameters)
333
- val lengths = IntArray (parameters)
334
- val formats = IntArray (parameters)
335
- val types = UIntArray (parameters)
333
+ internal val lengths = IntArray (parameters)
334
+ internal val formats = IntArray (parameters)
335
+ internal val types = UIntArray (parameters)
336
336
337
337
private fun bind (index : Int , value : String? , oid : UInt ) {
338
338
lengths[index] = if (value != null ) {
@@ -368,32 +368,32 @@ class PostgresPreparedStatement(private val parameters: Int) : SqlPreparedStatem
368
368
bind(index, string, textOid)
369
369
}
370
370
371
- fun bindDate (index : Int , value : LocalDate ? ) {
371
+ public fun bindDate (index : Int , value : LocalDate ? ) {
372
372
bind(index, value?.toString(), dateOid)
373
373
}
374
374
375
375
376
- fun bindTime (index : Int , value : LocalTime ? ) {
376
+ public fun bindTime (index : Int , value : LocalTime ? ) {
377
377
bind(index, value?.toString(), timeOid)
378
378
}
379
379
380
- fun bindLocalTimestamp (index : Int , value : LocalDateTime ? ) {
380
+ public fun bindLocalTimestamp (index : Int , value : LocalDateTime ? ) {
381
381
bind(index, value?.toString(), timestampOid)
382
382
}
383
383
384
- fun bindTimestamp (index : Int , value : Instant ? ) {
384
+ public fun bindTimestamp (index : Int , value : Instant ? ) {
385
385
bind(index, value?.toString(), timestampTzOid)
386
386
}
387
387
388
- fun bindInterval (index : Int , value : Duration ? ) {
388
+ public fun bindInterval (index : Int , value : Duration ? ) {
389
389
bind(index, value?.toIsoString(), intervalOid)
390
390
}
391
391
392
- fun bindUUID (index : Int , value : UUID ? ) {
392
+ public fun bindUUID (index : Int , value : UUID ? ) {
393
393
bind(index, value?.toString(), uuidOid)
394
394
}
395
395
396
- companion object {
396
+ private companion object {
397
397
// Hardcoded, because not provided in libpq-fe.h for unknown reasons...
398
398
// select * from pg_type;
399
399
private const val boolOid = 16u
@@ -411,7 +411,7 @@ class PostgresPreparedStatement(private val parameters: Int) : SqlPreparedStatem
411
411
}
412
412
}
413
413
414
- fun PostgresNativeDriver (
414
+ public fun PostgresNativeDriver (
415
415
host : String , database : String , user : String , password : String , port : Int = 5432, options : String? = null
416
416
): PostgresNativeDriver {
417
417
val conn = PQsetdbLogin (
0 commit comments