我想在Vapor中使用FluentMySQL保存数据,但是我无法正确读取UUID。
如果我使用MariaDB提供的UUID()函数,一切都很好,但是如果我使用FluentMySQL,则UUID会混乱: (第一条记录:UUID()的使用,第二条记录:蒸气)
MariaDB [someDB]> select * from Poll;
+--------------------------------------+-------+---------+---------+--------+--------+
| id | title | option1 | option2 | votes1 | votes2 |
+--------------------------------------+-------+---------+---------+--------+--------+
| 88a18a58-2fcd-11ea-9f62-e283e8014c79 | test | bla | bla | 0 | 0 |
| 7??/.?E??*_P?v | bla | option1 | option2 | 1 | 2 |
+--------------------------------------+-------+---------+---------+--------+--------+
2 rows in set (0.00 sec)
这是我的模特
import Foundation
import FluentMySQL
import Vapor
struct Poll: Content,MySQLUUIdmodel,Migration {
typealias ID = UUID
static let entity: String = "Poll"
var id: UUID?
var title: String
var option1: String
var option2: String
var votes1: Int
var votes2: Int
}
这是我的桌子
MariaDB [someDB]> describe Poll;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| id | varchar(191) | YES | | NULL | |
| title | varchar(191) | YES | | NULL | |
| option1 | varchar(191) | YES | | NULL | |
| option2 | varchar(191) | YES | | NULL | |
| votes1 | int(10) | YES | | NULL | |
| votes2 | int(10) | YES | | NULL | |
+---------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
但是如果使用Vapor来获取数据,一切似乎都很好。我在做什么错了?
通过curl输出:
curl http://locurl http://localhost:8080/polls/list
[{"option1":"bla","id":"38386131-3861-3538-2D32-6663642D3131","title":"test","option2":"bla","votes1":0,"votes2":0},{"option1":"option1","id":"373F3F2F-2E3F-453F-3F0E-2A5F503F7607","title":"bla","option2":"option2","votes1":1,"votes2":2}]
谢谢您的帮助。