-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Swift Vapor-Save records in Mysql JSON data type during mapping with swift get error- Could not convert MySQL data to String: <MYSQL_TYPE_JSON #3152
Comments
@rnrajput Sorry, but all the local telepaths are on vacation right now, dude. |
func prepare(on database: Database) async throws { try await database.schema("master_Interface_tb") .id() .field("customer_id", .string, .required) .field("page_name", .string,.required) .field("page_json", .custom("JSONB"), .required) .create() } final class MasterInterface: Model, Content { static let schema = "master_Interface_tb" @id(key: .id) var id: UUID? @field(key:"customer_id") var customerId: String @field(key:"page_name") var pageName: String @field(key:"page_json") var pageJson: String? init() { } init(id: UUID? = nil, customerId: String, pageName: String, pageJson:String?) { self.id = id self.customerId = customerId self.pageName = pageName self.pageJson = pageJson } } |
@rnrajput First, we format your code:
Next, let's look at the correspondence between the table schema and the corresponding model. We can see that for
If you have a You should read the relevant basic sections of the documentation: |
page_json column name as a JSON string . it is not JSON, same things work on when i post data it works successful |
The MySQL 8.0 documentation says the following: "JSON documents stored in JSON columns are converted to an internal format that permits quick read access to document elements. When the server later must read a JSON value stored in this binary format, the value need not be parsed from a text representation. The binary format is structured to enable the server to look up subobjects or nested values directly by key or array index without reading all values before or after them in the document." So, it's not a "JSON string", it's internal JSON representation and cannot be read as If you want to write JSON as a string, want to read it as a string and work with it as a string, then you should define a |
@mkll thanks now is working in mysql changes as LONGTEXT |
Swift Vapor-Save records in Mysql JSON data type during mapping with swift get error- Could not convert MySQL data to String: <MYSQL_TYPE_JSON
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Environment
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: