@@ -19,20 +19,20 @@ import SPMSQLite3
19
19
#endif
20
20
21
21
/// A minimal SQLite wrapper.
22
- public final class SQLite {
22
+ package final class SQLite {
23
23
/// The location of the database.
24
- public let location : Location
24
+ package let location : Location
25
25
26
26
/// The configuration for the database.
27
- public let configuration : Configuration
27
+ package let configuration : Configuration
28
28
29
29
/// Pointer to the database.
30
30
let db : OpaquePointer
31
31
32
32
/// Create or open the database at the given path.
33
33
///
34
34
/// The database is opened in serialized mode.
35
- public init ( location: Location , configuration: Configuration = Configuration ( ) ) throws {
35
+ package init ( location: Location , configuration: Configuration = Configuration ( ) ) throws {
36
36
self . location = location
37
37
self . configuration = configuration
38
38
@@ -64,19 +64,19 @@ public final class SQLite {
64
64
}
65
65
66
66
@available ( * , deprecated, message: " use init(location:configuration) instead " )
67
- public convenience init ( dbPath: AbsolutePath ) throws {
67
+ package convenience init ( dbPath: AbsolutePath ) throws {
68
68
try self . init ( location: . path( dbPath) )
69
69
}
70
70
71
71
/// Prepare the given query.
72
- public func prepare( query: String ) throws -> PreparedStatement {
72
+ package func prepare( query: String ) throws -> PreparedStatement {
73
73
try PreparedStatement ( db: self . db, query: query)
74
74
}
75
75
76
76
/// Directly execute the given query.
77
77
///
78
78
/// Note: Use withCString for string arguments.
79
- public func exec( query queryString: String , args: [ CVarArg ] = [ ] , _ callback: SQLiteExecCallback ? = nil ) throws {
79
+ package func exec( query queryString: String , args: [ CVarArg ] = [ ] , _ callback: SQLiteExecCallback ? = nil ) throws {
80
80
let query = withVaList ( args) { ptr in
81
81
sqlite3_vmprintf ( queryString, ptr)
82
82
}
@@ -96,27 +96,27 @@ public final class SQLite {
96
96
}
97
97
}
98
98
99
- public func close( ) throws {
99
+ package func close( ) throws {
100
100
try Self . checkError { sqlite3_close ( db) }
101
101
}
102
102
103
- public typealias SQLiteExecCallback = ( [ Column ] ) -> Void
103
+ package typealias SQLiteExecCallback = ( [ Column ] ) -> Void
104
104
105
- public struct Configuration {
106
- public var busyTimeoutMilliseconds : Int32
107
- public var maxSizeInBytes : Int ?
105
+ package struct Configuration {
106
+ package var busyTimeoutMilliseconds : Int32
107
+ package var maxSizeInBytes : Int ?
108
108
109
109
// https://www.sqlite.org/pgszchng2016.html
110
110
private let defaultPageSizeInBytes = 1024
111
111
112
- public init ( ) {
112
+ package init ( ) {
113
113
self . busyTimeoutMilliseconds = 5000
114
114
self . maxSizeInBytes = . none
115
115
}
116
116
117
117
// FIXME: deprecated 12/2020, remove once clients migrated over
118
118
@available ( * , deprecated, message: " use busyTimeout instead " )
119
- public var busyTimeoutSeconds : Int32 {
119
+ package var busyTimeoutSeconds : Int32 {
120
120
get {
121
121
self . _busyTimeoutSeconds
122
122
} set {
@@ -133,7 +133,7 @@ public final class SQLite {
133
133
}
134
134
}
135
135
136
- public var maxSizeInMegabytes : Int ? {
136
+ package var maxSizeInMegabytes : Int ? {
137
137
get {
138
138
self . maxSizeInBytes. map { $0 / ( 1024 * 1024 ) }
139
139
}
@@ -142,12 +142,12 @@ public final class SQLite {
142
142
}
143
143
}
144
144
145
- public var maxPageCount : Int ? {
145
+ package var maxPageCount : Int ? {
146
146
self . maxSizeInBytes. map { $0 / self . defaultPageSizeInBytes }
147
147
}
148
148
}
149
149
150
- public enum Location {
150
+ package enum Location : Sendable {
151
151
case path( AbsolutePath )
152
152
case memory
153
153
case temporary
@@ -165,59 +165,59 @@ public final class SQLite {
165
165
}
166
166
167
167
/// Represents an sqlite value.
168
- public enum SQLiteValue {
168
+ package enum SQLiteValue {
169
169
case null
170
170
case string( String )
171
171
case int( Int )
172
172
case blob( Data )
173
173
}
174
174
175
175
/// Represents a row returned by called step() on a prepared statement.
176
- public struct Row {
176
+ package struct Row {
177
177
/// The pointer to the prepared statement.
178
178
let stmt : OpaquePointer
179
179
180
180
/// Get integer at the given column index.
181
- public func int( at index: Int32 ) -> Int {
181
+ package func int( at index: Int32 ) -> Int {
182
182
Int ( sqlite3_column_int64 ( self . stmt, index) )
183
183
}
184
184
185
185
/// Get blob data at the given column index.
186
- public func blob( at index: Int32 ) -> Data {
186
+ package func blob( at index: Int32 ) -> Data {
187
187
let bytes = sqlite3_column_blob ( stmt, index) !
188
188
let count = sqlite3_column_bytes ( stmt, index)
189
189
return Data ( bytes: bytes, count: Int ( count) )
190
190
}
191
191
192
192
/// Get string at the given column index.
193
- public func string( at index: Int32 ) -> String {
193
+ package func string( at index: Int32 ) -> String {
194
194
String ( cString: sqlite3_column_text ( self . stmt, index) )
195
195
}
196
196
}
197
197
198
- public struct Column {
199
- public var name : String
200
- public var value : String
198
+ package struct Column {
199
+ package var name : String
200
+ package var value : String
201
201
}
202
202
203
203
/// Represents a prepared statement.
204
- public struct PreparedStatement {
204
+ package struct PreparedStatement {
205
205
typealias sqlite3_destructor_type = @convention ( c) ( UnsafeMutableRawPointer ? ) -> Void
206
206
static let SQLITE_STATIC = unsafeBitCast ( 0 , to: sqlite3_destructor_type. self)
207
207
static let SQLITE_TRANSIENT = unsafeBitCast ( - 1 , to: sqlite3_destructor_type. self)
208
208
209
209
/// The pointer to the prepared statement.
210
210
let stmt : OpaquePointer
211
211
212
- public init ( db: OpaquePointer , query: String ) throws {
212
+ package init ( db: OpaquePointer , query: String ) throws {
213
213
var stmt : OpaquePointer ?
214
214
try SQLite . checkError { sqlite3_prepare_v2 ( db, query, - 1 , & stmt, nil ) }
215
215
self . stmt = stmt!
216
216
}
217
217
218
218
/// Evaluate the prepared statement.
219
219
@discardableResult
220
- public func step( ) throws -> Row ? {
220
+ package func step( ) throws -> Row ? {
221
221
let result = sqlite3_step ( stmt)
222
222
223
223
switch result {
@@ -231,7 +231,7 @@ public final class SQLite {
231
231
}
232
232
233
233
/// Bind the given arguments to the statement.
234
- public func bind( _ arguments: [ SQLiteValue ] ) throws {
234
+ package func bind( _ arguments: [ SQLiteValue ] ) throws {
235
235
for (idx, argument) in arguments. enumerated ( ) {
236
236
let idx = Int32 ( idx) + 1
237
237
switch argument {
@@ -258,17 +258,17 @@ public final class SQLite {
258
258
}
259
259
260
260
/// Reset the prepared statement.
261
- public func reset( ) throws {
261
+ package func reset( ) throws {
262
262
try SQLite . checkError { sqlite3_reset ( stmt) }
263
263
}
264
264
265
265
/// Clear bindings from the prepared statement.
266
- public func clearBindings( ) throws {
266
+ package func clearBindings( ) throws {
267
267
try SQLite . checkError { sqlite3_clear_bindings ( stmt) }
268
268
}
269
269
270
270
/// Finalize the statement and free up resources.
271
- public func finalize( ) throws {
271
+ package func finalize( ) throws {
272
272
try SQLite . checkError { sqlite3_finalize ( stmt) }
273
273
}
274
274
}
@@ -296,7 +296,7 @@ public final class SQLite {
296
296
}
297
297
}
298
298
299
- public enum Errors : Error {
299
+ package enum Errors : Error {
300
300
case databaseFull
301
301
}
302
302
}
0 commit comments