I have an column defined like this:
@Column(nullable: true)
Document openHours; // List "openHours": ["Tuesday - Sunday: 11.00 - 21.00"],
In my migration file i use seed():
@override
Future seed() async {
const sClientSQL = ...
and the json part that throws me out, is:
"openHours": [
"Monday - Friday: 17.00 - 22.00",
"Saturday: 14:00 - 23:00",
"Sunday & Holidays: 11:30 - 22:00"
],
Error in Terminal looks like:
Seeding data from migration version 1...
*** There was an issue. Reason: Could not infer type of value '[Monday - Friday: 17.00 - 22.00,
Saturday: 14:00 - 23:00, Sunday & Holidays: 11:30 - 22:00]'.. Table: null Column: null
Documentation says:
Document map or list (Map<String, dynamic> or List<dynamic>)
JSON Looks ok to me, but obviously in this context it's wrong. So what am i doing wrong here? I couldn't find an example on how to code the json part for type Document in aqueduct.
Thank all and regards Antonio
[Edit 4]
Here is a shortened example of the query that:
const sClientSQL = 'INSERT INTO _Clients (name, owner, address, contacts, openhours, dayOff, description) VALUES (@name, @owner, @address, @contacts, @openhours, @dayOff, @description)';
await database.store.execute(sClientSQL, substitutionValues: {
'name': 'Dolce Vita',
'owner': 'David Driss',
'address': {
'street': 'Johannisstr. 3',
'zipCode': '54290',
'city': 'Trier'
},
'contacts': {
'phone': '0651 94 90 40',
'fax': '0651 43 23 2',
'mail': '[email protected]'
},
'openhours': [
"Montag - Freitag: 17.00 - 22.00",
"Samstag: 14:00 - 23:00",
"Sonntag & Feiertag: 11:30 - 22:00"
],
'dayOff': '',
'description': 'Alle Speisen und Getränke sind inkl. MwST. Extrazutaten werden gesondert berechnet'
});
[Edit 1]
Further Information:
substitution values is as Map.
I used double quotes, and changed it to single quotes, that didn't have effect.
[EDIT 2]
Tried out complex map in dartpad and created a gist to show:
Gist to Dart Maps sample put the code in to dartpad.
Result The map as it is, is valid.
[EDIT 3]
So, only the await database.store.execute
command doesn't want my json type literal.
With the help from a user on an other channel i finally figured out, how to get it work.
The magic is all about using the right syntax and it's been a lot trial and error, wonder where to find the docs about it?
Working Examples
all following "fields" in substitutionValues are jsonb columns in database
await database.store.execute(sClientSQL, substitutionValues: {
'address': {
'street': 'a street',
'zipCode': '123456',
'city': 'mycity'
},
'contacts': {
'phone': '12345678',
'fax': '12346578',
'mail': '[email protected]'
},
'openhours': '''[
"Monday - Friday: 17.00 - 22.00",
"Saturday: 14:00 - 23:00",
"Sunday: 11:30 - 22:00"
]''',
'fees': '''[
{"delivery": 2.00, "minOrder": 7.50, "location": "all"},
{"delivery": 2.50, "minOrder": 9.50, "location": "here"},
{"delivery": 2.50, "minOrder": 9.50, "location": "there"}
]''',
I think that with these we get all complexity done.