Comments (6)
@mkll thanks now is working in mysql changes as LONGTEXT
from vapor.
@rnrajput Sorry, but all the local telepaths are on vacation right now, dude.
¯\(ツ)/¯
from vapor.
from vapor.
@rnrajput First, we format your code:
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
}
}
Next, let's look at the correspondence between the table schema and the corresponding model.
We can see that for page_json
column name you have JSON
definition in your schema and String
definition in your model, and that the error message you receive matches your code exactly. It couldn't be any other way.
JSON
definition in a schema is used when another nested model is stored in the corresponding model variable. In this case, the database driver automatically encodes and decodes the entire model hierarchy.
If you have a String
property in your model, then in the schema the corresponding field should also be defined as String
.
You should read the relevant basic sections of the documentation:
https://docs.vapor.codes/fluent/schema/#dictionary
from vapor.
page_json column name as a JSON string . it is not JSON, same things work on when i post data it works successful { "customerId":"AB02", "pageName": "LoginPage", "pageJson": "{\"loginPage\":{\"navigationTitle\":\"LoginPage\",\"navigationFontSize\":20,\"navigationTitleColor\":\"#000000\",\"alignment\":\"center\"}}" }
from vapor.
page_json column name as a JSON string . it is not JSON
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 String
. Exactly the same thing the error message says ("Could not convert MySQL data to String: <MYSQL_TYPE_JSON").
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 .string
data type in the column rather than JSON. This is exactly how it works.
from vapor.
Related Issues (20)
- Vapor migrations do not finish running on fly.io HOT 8
- Documentation for cache HOT 5
- Unable to test vapor using .xcodeproj project HOT 8
- Response compression handler not added for HTTP2 requests
- Updating HTTP server configuration on the fly (ie. TLS settings) HOT 3
- Double encoded post requests after recent update (4.89.3 → 4.91.1) HOT 1
- UserAuthnetication middleware is bypassed when auth object is not used HOT 2
- Query decoding broken in 4.90 HOT 3
- vapor and toolbox compile error on arch linux HOT 1
- double slash in URL no longer matches route handlers HOT 3
- URI semantics are broken HOT 1
- commùit
- Double slash in URLs still breaks route matching with variable parts in vapor 4.92.0 HOT 2
- Trying to build on Ubuntu 20 with swift run and getting Building for debugging... error: emit-module command failed due to signal 9 HOT 2
- Unable to shutdown server HOT 1
- Title
- Vapor URLQueryContainer no longer supports valueless query parameters HOT 4
- Large, streamed request body may result in noSignalReceived preconditionFailure crash HOT 6
- Websocket shouldUpgrade() fail causes empty reply from server HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.