diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..0a22eec --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [tanner0101] # loganwright, joscdk +open_collective: vapor diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..36ca51a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: test +on: +- pull_request +jobs: + bionic: + container: + image: vapor/swift:5.1-bionic + runs-on: ubuntu-latest + steps: + - run: apt update -y; apt install -y libsqlite3-dev + - uses: actions/checkout@master + - run: swift test + xenial: + container: + image: vapor/swift:5.1-xenial + runs-on: ubuntu-latest + steps: + - run: apt update -y; apt install -y libsqlite3-dev + - uses: actions/checkout@master + - run: swift test + thread: + container: + image: vapor/swift:5.1 + runs-on: ubuntu-latest + steps: + - run: apt update -y; apt install -y libsqlite3-dev + - uses: actions/checkout@master + - run: swift test --sanitize=thread diff --git a/Package.swift b/Package.swift index d586553..7c20301 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.0.0-alpha"), .package(url: "https://github.com/vapor/sql-kit.git", from: "3.0.0-alpha"), - .package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0-alpha"), + .package(url: "https://github.com/vapor/async-kit.git", .branch("master")), ], targets: [ .target(name: "SQLiteKit", dependencies: [ diff --git a/Sources/SQLiteKit/SQLiteConnectionSource.swift b/Sources/SQLiteKit/SQLiteConnectionSource.swift index 2ae5b2c..3fc2d9f 100644 --- a/Sources/SQLiteKit/SQLiteConnectionSource.swift +++ b/Sources/SQLiteKit/SQLiteConnectionSource.swift @@ -1,7 +1,6 @@ import Logging public final class SQLiteConnectionSource: ConnectionPoolSource { - public var eventLoop: EventLoop private let storage: SQLiteConnection.Storage private let threadPool: NIOThreadPool private let logger: Logger @@ -9,8 +8,7 @@ public final class SQLiteConnectionSource: ConnectionPoolSource { public init( configuration: SQLiteConfiguration, threadPool: NIOThreadPool, - logger: Logger = .init(label: "codes.sqlite.connection-source"), - on eventLoop: EventLoop + logger: Logger = .init(label: "codes.sqlite.connection-source") ) { switch configuration.storage { case .memory: @@ -20,11 +18,10 @@ public final class SQLiteConnectionSource: ConnectionPoolSource { } self.threadPool = threadPool self.logger = logger - self.eventLoop = eventLoop } - public func makeConnection() -> EventLoopFuture { - return SQLiteConnection.open(storage: self.storage, threadPool: self.threadPool, on: self.eventLoop) + public func makeConnection(on eventLoop: EventLoop) -> EventLoopFuture { + return SQLiteConnection.open(storage: self.storage, threadPool: self.threadPool, on: eventLoop) } } diff --git a/Sources/SQLiteKit/SQLiteDialect.swift b/Sources/SQLiteKit/SQLiteDialect.swift index b07a409..167d6f3 100644 --- a/Sources/SQLiteKit/SQLiteDialect.swift +++ b/Sources/SQLiteKit/SQLiteDialect.swift @@ -1,28 +1,30 @@ -struct SQLiteDialect: SQLDialect { - var identifierQuote: SQLExpression { +public struct SQLiteDialect: SQLDialect { + public var identifierQuote: SQLExpression { return SQLRaw("'") } - var literalStringQuote: SQLExpression { + public var literalStringQuote: SQLExpression { return SQLRaw("\"") } - var autoIncrementClause: SQLExpression { + public var autoIncrementClause: SQLExpression { return SQLRaw("AUTOINCREMENT") } - mutating func nextBindPlaceholder() -> SQLExpression { + public mutating func nextBindPlaceholder() -> SQLExpression { return SQLRaw("?") } - func literalBoolean(_ value: Bool) -> SQLExpression { + public func literalBoolean(_ value: Bool) -> SQLExpression { switch value { case true: return SQLRaw("TRUE") case false: return SQLRaw("FALSE") } } - var literalDefault: SQLExpression { + public var literalDefault: SQLExpression { return SQLLiteral.null } + + public init() { } } diff --git a/Tests/SQLiteKitTests/SQLKitTests.swift b/Tests/SQLiteKitTests/SQLKitTests.swift index 62e1da0..38bf8f1 100644 --- a/Tests/SQLiteKitTests/SQLKitTests.swift +++ b/Tests/SQLiteKitTests/SQLKitTests.swift @@ -87,12 +87,12 @@ class SQLiteTests: XCTestCase { override func setUp() { self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) self.threadPool = .init(numberOfThreads: 2) - let db = SQLiteConnectionSource(configuration: .init(storage: .memory), threadPool: self.threadPool, on: self.eventLoopGroup.next()) - self.db = ConnectionPool(config: .init(maxConnections: 8), source: db) + let db = SQLiteConnectionSource(configuration: .init(storage: .memory), threadPool: self.threadPool) + self.db = ConnectionPool(configuration: .init(maxConnections: 8), source: db, on: self.eventLoopGroup) } override func tearDown() { - try! self.db.close().wait() + self.db.shutdown() self.db = nil try! self.threadPool.syncShutdownGracefully() self.threadPool = nil