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

Fluent cannot decode utf8mb4_unicode_ci to string from mysql #714

Open
pankajsoni19 opened this issue Jan 4, 2021 · 0 comments
Open

Fluent cannot decode utf8mb4_unicode_ci to string from mysql #714

pankajsoni19 opened this issue Jan 4, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@pankajsoni19
Copy link

Describe the bug

Fail to decode data correctly to string from mysql.

To Reproduce

Mariadb: AWS RDS

> SELECT VERSION();
>> 10.4.13-MariaDB-log
CREATE TABLE `channels` (
  `channel` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
  PRIMARY KEY (`channel`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Insert into table

INSERT INTO `channels` (`channel`)
VALUES ('zafé');

Vapor model: Channel.swift


import Vapor
import Fluent
import FluentSQL

final class Channel: Model {
   
    static let schema = "channels"
    
    public init() { }
    
    @ID(custom: "channel", generatedBy: .user)
    var id: String?
    
    @Timestamp(key: "created_at", on: .create)
    var created_at: Date?
}

extension Channel: Content { }

Read value

Channel.query(on: appInstance.db).all().whenSuccess { (channels: [Channel]) in
    channels.forEach { (channel: Channel) in
        print("meta: \(channel.id) ")
    }
}

Expected: meta: zafé
Actual: meta: zaf�

Package.swift

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "Server",
    platforms: [
        .macOS(.v10_15)
    ],
    products: [
        .library(name: "Server", targets: ["App"]), // product name
    ],
    dependencies: [
        .package(url: "https://github.com/vapor/vapor.git", from: "4.35.0"), //vapor dep
        .package(url: "https://github.com/vapor/leaf.git", from: "4.0.0"),
        .package(url: "https://github.com/soto-project/soto.git", from: "5.0.0"), //aws sdk
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"),    // DB ORM
        .package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0"), //mysql
        .package(url: "https://github.com/vapor/redis.git", from: "4.0.0"), //redis
        .package(url: "https://github.com/CoreOffice/CoreXLSX.git", .upToNextMinor(from: "0.13.0")), //xlsx decoding
        .package(url: "https://github.com/pankajsoni19/swift-backtrace.git", from: "1.4.0") //swift error logging utility
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "SotoS3", package: "soto"),
                .product(name: "SotoSES", package: "soto"),

                .product(name: "Leaf", package: "leaf"),
                .product(name: "Fluent", package: "fluent"),
                .product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
                .product(name: "Vapor", package: "vapor"),

                .product(name: "Redis", package: "redis"),
                .product(name: "CoreXLSX", package: "CoreXLSX"),
                .product(name: "Backtrace", package: "swift-backtrace")
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
        ]),
        .target(name: "Run", dependencies: [
            .target(name: "App")
        ])
    ]
)

@pankajsoni19 pankajsoni19 added the bug Something isn't working label Jan 4, 2021
@pankajsoni19 pankajsoni19 changed the title Fluent cannot decode utf8mb4_unicode_ci to string Fluent cannot decode utf8mb4_unicode_ci to string from mysql Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant