Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async-kit connection pool updates #59

Merged
merged 2 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [tanner0101] # loganwright, joscdk
open_collective: vapor
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
9 changes: 3 additions & 6 deletions Sources/SQLiteKit/SQLiteConnectionSource.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import Logging

public final class SQLiteConnectionSource: ConnectionPoolSource {
public var eventLoop: EventLoop
private let storage: SQLiteConnection.Storage
private let threadPool: NIOThreadPool
private let logger: Logger

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:
Expand All @@ -20,11 +18,10 @@ public final class SQLiteConnectionSource: ConnectionPoolSource {
}
self.threadPool = threadPool
self.logger = logger
self.eventLoop = eventLoop
}

public func makeConnection() -> EventLoopFuture<SQLiteConnection> {
return SQLiteConnection.open(storage: self.storage, threadPool: self.threadPool, on: self.eventLoop)
public func makeConnection(on eventLoop: EventLoop) -> EventLoopFuture<SQLiteConnection> {
return SQLiteConnection.open(storage: self.storage, threadPool: self.threadPool, on: eventLoop)
}
}

Expand Down
16 changes: 9 additions & 7 deletions Sources/SQLiteKit/SQLiteDialect.swift
Original file line number Diff line number Diff line change
@@ -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() { }
}
6 changes: 3 additions & 3 deletions Tests/SQLiteKitTests/SQLKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down