mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
36 lines
1.0 KiB
Swift
36 lines
1.0 KiB
Swift
//
|
|
// Database.swift
|
|
// GRDB
|
|
//
|
|
// Created by Gwendal Roué on 30/06/2015.
|
|
// Copyright © 2015 Gwendal Roué. All rights reserved.
|
|
//
|
|
|
|
typealias CConnection = COpaquePointer
|
|
|
|
public class Database {
|
|
let cConnection = CConnection()
|
|
|
|
public init(path: String) throws {
|
|
// See https://www.sqlite.org/c3ref/open.html
|
|
let code = path.nulTerminatedUTF8.withUnsafeBufferPointer { codeUnits in
|
|
return sqlite3_open(UnsafePointer<Int8>(codeUnits.baseAddress), &cConnection)
|
|
}
|
|
try Error.checkCResultCode(code, cConnection: cConnection)
|
|
}
|
|
|
|
deinit {
|
|
if cConnection != nil {
|
|
sqlite3_close(cConnection)
|
|
}
|
|
}
|
|
|
|
public func rowSequenceWithQuery(query: String) throws -> RowSequence {
|
|
return try RowSequence(cConnection: cConnection, query: query)
|
|
}
|
|
|
|
public func updateStatementWithQuery(query: String) throws -> UpdateStatement {
|
|
return try UpdateStatement(cConnection: cConnection, query: query)
|
|
}
|
|
}
|