Skip to content
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
29 changes: 19 additions & 10 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import PackageDescription

let package = Package(
name: "feather-relational-database-driver-mysql",
name: "feather-database-driver-mysql",
platforms: [
.macOS(.v13),
.iOS(.v16),
Expand All @@ -11,24 +11,25 @@ let package = Package(
.visionOS(.v1),
],
products: [
.library(name: "FeatherRelationalDatabaseDriverMySQL", targets: ["FeatherRelationalDatabaseDriverMySQL"]),
.library(name: "FeatherDatabaseDriverMySQL", targets: ["FeatherDatabaseDriverMySQL"]),
],
dependencies: [
.package(url: "https://github.com/feather-framework/feather-relational-database", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/feather-framework/feather-database", .upToNextMinor(from: "0.4.0")),
.package(url: "https://github.com/vapor/mysql-kit", from: "4.7.0"),
],
targets: [
.target(
name: "FeatherRelationalDatabaseDriverMySQL",
name: "FeatherDatabaseDriverMySQL",
dependencies: [
.product(name: "FeatherRelationalDatabase", package: "feather-relational-database"),
.product(name: "FeatherDatabase", package: "feather-database"),
.product(name: "MySQLKit", package: "mysql-kit"),
]
),
.testTarget(
name: "FeatherRelationalDatabaseDriverMySQLTests",
name: "FeatherDatabaseDriverMySQLTests",
dependencies: [
.target(name: "FeatherRelationalDatabaseDriverMySQL"),
.product(name: "FeatherDatabaseTesting", package: "feather-database"),
.target(name: "FeatherDatabaseDriverMySQL"),
]
),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// File 2.swift
//
//
// Created by Tibor Bodecs on 03/12/2023.
//

import AsyncKit
import FeatherComponent
import FeatherDatabase
import MySQLKit
import SQLKit

@dynamicMemberLookup
struct MySQLDatabaseComponent: DatabaseComponent {

public let config: ComponentConfig

subscript<T>(
dynamicMember keyPath: KeyPath<
MySQLDatabaseComponentContext, T
>
) -> T {
let context = config.context as! MySQLDatabaseComponentContext
return context[keyPath: keyPath]
}

public func connection() async throws -> Database {
.init(self.pool.database(logger: self.logger).sql())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import FeatherComponent
@preconcurrency import MySQLKit

public struct MySQLRelationalDatabaseComponentContext: ComponentContext {
public struct MySQLDatabaseComponentContext: ComponentContext {

let pool: EventLoopGroupConnectionPool<MySQLConnectionSource>

Expand All @@ -19,6 +19,6 @@ public struct MySQLRelationalDatabaseComponentContext: ComponentContext {
}

public func make() throws -> ComponentFactory {
MySQLRelationalDatabaseComponentFactory(context: self)
MySQLDatabaseComponentFactory(context: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import AsyncKit
import FeatherComponent
import MySQLKit

struct MySQLRelationalDatabaseComponentFactory: ComponentFactory {
struct MySQLDatabaseComponentFactory: ComponentFactory {

let context: MySQLRelationalDatabaseComponentContext
let context: MySQLDatabaseComponentContext

func build(using config: ComponentConfig) throws -> Component {
MySQLRelationalDatabaseComponent(config: config)
MySQLDatabaseComponent(config: config)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// FeatherSQLDatabaseTests.swift
// FeatherSQLDatabaseTests
//
// Created by Tibor Bodecs on 2023. 01. 16..
//

import FeatherComponent
import FeatherDatabase
import FeatherDatabaseDriverMySQL
import FeatherDatabaseTesting
import MySQLKit
import NIO
import XCTest

final class FeatherDatabaseDriverMySQLTests: XCTestCase {

var host: String {
ProcessInfo.processInfo.environment["MYSQL_HOST"]!
}

var user: String {
ProcessInfo.processInfo.environment["MYSQL_USER"]!
}

var pass: String {
ProcessInfo.processInfo.environment["MYSQL_PASS"]!
}

var db: String {
ProcessInfo.processInfo.environment["MYSQL_DB"]!
}

func testExample() async throws {
let registry = ComponentRegistry()

let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let threadPool = NIOThreadPool(numberOfThreads: 1)
threadPool.start()

var config = TLSConfiguration.makeClientConfiguration()
config.certificateVerification = .none

let configuration = MySQLConfiguration(
hostname: host,
username: user,
password: pass,
database: db,
tlsConfiguration: config
)
let connectionSource = MySQLConnectionSource(
configuration: configuration
)
let pool = EventLoopGroupConnectionPool<MySQLConnectionSource>
.init(
source: connectionSource,
on: eventLoopGroup
)

try await registry.addDatabase(
MySQLDatabaseComponentContext(pool: pool)
)

let db = try await registry.database()
let testSuite = DatabaseTestSuite(db)
try await testSuite.testAll()

pool.shutdown()
try await eventLoopGroup.shutdownGracefully()
try await threadPool.shutdownGracefully()
}
}

This file was deleted.