1
1
import CLibsql
2
2
import Foundation
3
3
4
- enum Value {
4
+ public enum Value {
5
5
case integer( Int64 )
6
6
case text( String )
7
7
case blob( Data )
8
8
case real( Double )
9
9
case null
10
10
}
11
11
12
- protocol ValueRepresentable {
12
+ public protocol ValueRepresentable {
13
13
func toValue( ) -> Value
14
14
}
15
15
16
16
extension Value : ValueRepresentable {
17
- func toValue( ) -> Value { self }
17
+ public func toValue( ) -> Value { self }
18
18
}
19
19
20
20
extension Int : ValueRepresentable {
21
- func toValue( ) -> Value { . integer( Int64 ( self ) ) }
21
+ public func toValue( ) -> Value { . integer( Int64 ( self ) ) }
22
22
}
23
23
24
24
extension Int64 : ValueRepresentable {
25
- func toValue( ) -> Value { . integer( self ) }
25
+ public func toValue( ) -> Value { . integer( self ) }
26
26
}
27
27
28
28
extension String : ValueRepresentable {
29
- func toValue( ) -> Value { . text( self ) }
29
+ public func toValue( ) -> Value { . text( self ) }
30
30
}
31
31
32
32
extension Data : ValueRepresentable {
33
- func toValue( ) -> Value { . blob( self ) }
33
+ public func toValue( ) -> Value { . blob( self ) }
34
34
}
35
35
36
36
extension Double : ValueRepresentable {
37
- func toValue( ) -> Value { . real( self ) }
37
+ public func toValue( ) -> Value { . real( self ) }
38
38
}
39
39
40
40
extension String ? {
@@ -52,7 +52,7 @@ enum LibsqlError: Error {
52
52
case unexpectedType
53
53
}
54
54
55
- class Row {
55
+ public class Row {
56
56
var inner : libsql_row_t
57
57
58
58
fileprivate init ? ( fromPtr inner: libsql_row_t ? ) {
@@ -63,7 +63,7 @@ class Row {
63
63
self . inner = inner
64
64
}
65
65
66
- func getData( _ index: Int32 ) throws -> Data {
66
+ public func getData( _ index: Int32 ) throws -> Data {
67
67
var slice : blob = blob ( )
68
68
69
69
var err : UnsafePointer < CChar > ?
@@ -77,7 +77,7 @@ class Row {
77
77
return Data ( bytes: slice. ptr, count: Int ( slice. len) )
78
78
}
79
79
80
- func getDouble( _ index: Int32 ) throws -> Double {
80
+ public func getDouble( _ index: Int32 ) throws -> Double {
81
81
var double : Double = 0
82
82
83
83
var err : UnsafePointer < CChar > ?
@@ -89,7 +89,7 @@ class Row {
89
89
return double
90
90
}
91
91
92
- func getString( _ index: Int32 ) throws -> String {
92
+ public func getString( _ index: Int32 ) throws -> String {
93
93
var string : UnsafePointer < CChar > ? = nil
94
94
95
95
var err : UnsafePointer < CChar > ?
@@ -103,7 +103,7 @@ class Row {
103
103
return String ( cString: string!)
104
104
}
105
105
106
- func getInt( _ index: Int32 ) throws -> Int {
106
+ public func getInt( _ index: Int32 ) throws -> Int {
107
107
var integer : Int64 = 0
108
108
109
109
var err : UnsafePointer < CChar > ?
@@ -116,7 +116,7 @@ class Row {
116
116
}
117
117
}
118
118
119
- class Rows : Sequence , IteratorProtocol {
119
+ public class Rows : Sequence , IteratorProtocol {
120
120
var inner : libsql_rows_t
121
121
122
122
fileprivate init ( fromPtr inner: libsql_rows_t ) {
@@ -127,7 +127,7 @@ class Rows: Sequence, IteratorProtocol {
127
127
libsql_free_rows ( self . inner)
128
128
}
129
129
130
- func next( ) -> Row ? {
130
+ public func next( ) -> Row ? {
131
131
var row : libsql_row_t ?
132
132
133
133
var err : UnsafePointer < CChar > ?
@@ -140,7 +140,7 @@ class Rows: Sequence, IteratorProtocol {
140
140
}
141
141
}
142
142
143
- class Statement {
143
+ public class Statement {
144
144
var inner : libsql_stmt_t
145
145
146
146
deinit {
@@ -151,25 +151,25 @@ class Statement {
151
151
self . inner = inner
152
152
}
153
153
154
- func execute( ) throws {
154
+ public func execute( ) throws {
155
155
var err : UnsafePointer < CChar > ? = nil
156
156
if libsql_execute_stmt ( self . inner, & err) != 0 {
157
157
defer { libsql_free_string ( err) }
158
158
throw LibsqlError . runtimeError ( String ( cString: err!) )
159
159
}
160
160
}
161
161
162
- func execute( _ params: [ ValueRepresentable ] ) throws {
162
+ public func execute( _ params: [ ValueRepresentable ] ) throws {
163
163
try self . bind ( params)
164
164
return try self . execute ( )
165
165
}
166
166
167
- func execute( _ params: ValueRepresentable ... ) throws {
167
+ public func execute( _ params: ValueRepresentable ... ) throws {
168
168
try self . bind ( params)
169
169
return try self . execute ( )
170
170
}
171
171
172
- func query( ) throws -> Rows {
172
+ public func query( ) throws -> Rows {
173
173
var rows : libsql_rows_t ? = nil
174
174
175
175
var err : UnsafePointer < CChar > ? = nil
@@ -181,21 +181,21 @@ class Statement {
181
181
return Rows ( fromPtr: rows!)
182
182
}
183
183
184
- func query( _ params: [ ValueRepresentable ] ) throws -> Rows {
184
+ public func query( _ params: [ ValueRepresentable ] ) throws -> Rows {
185
185
try self . bind ( params)
186
186
return try self . query ( )
187
187
}
188
188
189
- func query( _ params: ValueRepresentable ... ) throws -> Rows {
189
+ public func query( _ params: ValueRepresentable ... ) throws -> Rows {
190
190
try self . bind ( params)
191
191
return try self . query ( )
192
192
}
193
193
194
- func bind( _ params: ValueRepresentable ... ) throws {
194
+ public func bind( _ params: ValueRepresentable ... ) throws {
195
195
return try self . bind ( params)
196
196
}
197
197
198
- func bind( _ params: [ ValueRepresentable ] ) throws {
198
+ public func bind( _ params: [ ValueRepresentable ] ) throws {
199
199
for (i, v) in params. enumerated ( ) {
200
200
let i = Int32 ( i + 1 )
201
201
@@ -242,7 +242,7 @@ class Statement {
242
242
}
243
243
}
244
244
245
- class Connection {
245
+ public class Connection {
246
246
var inner : libsql_connection_t
247
247
248
248
deinit {
@@ -253,7 +253,7 @@ class Connection {
253
253
self . inner = inner
254
254
}
255
255
256
- func query( _ sql: String ) throws -> Rows {
256
+ public func query( _ sql: String ) throws -> Rows {
257
257
var rows : libsql_rows_t ? = nil
258
258
try sql. withCString { sql in
259
259
var err : UnsafePointer < CChar > ? = nil
@@ -266,16 +266,16 @@ class Connection {
266
266
return Rows ( fromPtr: rows!)
267
267
}
268
268
269
- func query( _ sql: String , _ params: [ ValueRepresentable ] ) throws -> Rows {
269
+ public func query( _ sql: String , _ params: [ ValueRepresentable ] ) throws -> Rows {
270
270
let stmt = try self . prepare ( sql)
271
271
return try stmt. query ( params)
272
272
}
273
273
274
- func query( _ sql: String , _ params: ValueRepresentable ... ) throws -> Rows {
274
+ public func query( _ sql: String , _ params: ValueRepresentable ... ) throws -> Rows {
275
275
return try self . query ( sql, params as [ ValueRepresentable ] )
276
276
}
277
277
278
- func execute( _ sql: String ) throws {
278
+ public func execute( _ sql: String ) throws {
279
279
try sql. withCString { sql in
280
280
var err : UnsafePointer < CChar > ? = nil
281
281
if libsql_execute ( self . inner, sql, & err) != 0 {
@@ -285,16 +285,16 @@ class Connection {
285
285
}
286
286
}
287
287
288
- func execute( _ sql: String , _ params: [ ValueRepresentable ] ) throws {
288
+ public func execute( _ sql: String , _ params: [ ValueRepresentable ] ) throws {
289
289
let stmt = try self . prepare ( sql)
290
290
return try stmt. execute ( params)
291
291
}
292
292
293
- func execute( _ sql: String , _ params: ValueRepresentable ... ) throws {
293
+ public func execute( _ sql: String , _ params: ValueRepresentable ... ) throws {
294
294
return try self . execute ( sql, params as [ ValueRepresentable ] )
295
295
}
296
296
297
- func prepare( _ sql: String ) throws -> Statement {
297
+ public func prepare( _ sql: String ) throws -> Statement {
298
298
var stmt : libsql_stmt_t ? = nil
299
299
300
300
try sql. withCString { sql in
@@ -309,22 +309,22 @@ class Connection {
309
309
}
310
310
}
311
311
312
- class Database {
312
+ public class Database {
313
313
var inner : libsql_database_t
314
314
315
315
deinit {
316
316
libsql_close ( self . inner)
317
317
}
318
318
319
- func sync( ) throws {
319
+ public func sync( ) throws {
320
320
var err : UnsafePointer < CChar > ? = nil
321
321
if libsql_sync ( self . inner, & err) != 0 {
322
322
defer { libsql_free_string ( err) }
323
323
throw LibsqlError . runtimeError ( String ( cString: err!) )
324
324
}
325
325
}
326
326
327
- func connect( ) throws -> Connection {
327
+ public func connect( ) throws -> Connection {
328
328
var conn : libsql_connection_t ? = nil
329
329
330
330
var err : UnsafePointer < CChar > ? = nil
@@ -336,7 +336,7 @@ class Database {
336
336
return Connection ( fromPtr: conn!)
337
337
}
338
338
339
- init ( _ path: String ) throws {
339
+ public init ( _ path: String ) throws {
340
340
var db : libsql_database_t ? = nil
341
341
342
342
try path. withCString { path in
@@ -350,7 +350,7 @@ class Database {
350
350
self . inner = db!
351
351
}
352
352
353
- init ( url: String , authToken: String , withWebpki: Bool = false ) throws {
353
+ public init ( url: String , authToken: String , withWebpki: Bool = false ) throws {
354
354
var db : libsql_database_t ? = nil
355
355
356
356
try url. withCString { url in
@@ -374,7 +374,7 @@ class Database {
374
374
self . inner = db!
375
375
}
376
376
377
- init (
377
+ public init (
378
378
path: String ,
379
379
url: String ,
380
380
authToken: String ,
0 commit comments