File tree Expand file tree Collapse file tree 1 file changed +29
-2
lines changed
Sources/StructuredQueriesSQLiteCore/Documentation.docc/Articles Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,35 @@ configuration.prepareDatabase { db in
5050
5151### Custom representations
5252
53- To define a type that works with a custom representation, like JSON, you can use the `as ` parameter
54- of the macro:
53+ To define a type that works with a custom representation, i.e . anytime you use `@Column (as : )` in
54+ your data type, you can use the `as ` parameter of the macro to specify those types. For example,
55+ if your model holds onto a date and you want to store that date as a
56+ [unix timestamp](< doc: Foundation/ Date/ UnixTimeRepresentation- struct> ) (i.e . double),
57+ then you can do so like this:
58+
59+ ```swift
60+ @Table
61+ struct Reminder {
62+ let id: UUID
63+ var title = " "
64+ @Column (as : Date.UnixTimeRepresentation .self )
65+ var dueDate: Date
66+ }
67+ ```
68+
69+ And if you wanted to pass this ` dueDate ` to a Swift database function, you can do so like this:
70+
71+ ``` swift
72+ @DatabaseFunction (
73+ as : ((Date.UnixTimeRepresentation .self ) -> Bool ).self
74+ )
75+ func isPastDue (_ date : Date) -> Bool {
76+ date < Date ()
77+ }
78+ ```
79+
80+ As another example, if you wanted to pass an array of strings from SQL to your Swift database
81+ function, then you can shuffle the data through using json:
5582
5683``` swift
5784@DatabaseFunction (
You can’t perform that action at this time.
0 commit comments