-
Why isn't I want to convert the value of a Also, as my ultimate goal is to get the value of a column as a Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello @mallman,
This is because
try db.create(table: "myTable") { t in
t.column("a", .boolean) // 1
t.column("b", ColumnType(rawValue: "BOOL")) // 2
t.column("c", ColumnType(rawValue: "PIKACHU")) // 3
} All of them are valid ways to declare columns that store booleans. 2 is original but quite OK; 3 is confusing but it won't create any runtime problem at all. That's how Datatypes In SQLite work. The library does not provide any interpretation of raw column types returned by If an application wants to perform a specific handling of columns with type "BOOLEAN", that's ok: To my eyes, the |
Beta Was this translation helpful? Give feedback.
-
Hi @groue. I believe I understand your reply, and it makes sense. Rather than introspecting on the SQLite column info type, how about introspecting on the GRDB migration schema? As a matter of API the user designs and defines the migrations. They provide a column type annotation of their choosing. It can be one of the convenient pre-defined values, or it can be "PIKACHU", et. al. The point is, they control what they put in there. They should be able to identify it when introspecting a table migration. Is it even possible to introspect on the schema definition? I don't see it stored in the table, and defining a stable serialized form for it may be a major pain in the ass. Another possibility is I can probably introspect on the Swift type of the At any rate, for my purposes, assuming the value of |
Beta Was this translation helpful? Give feedback.
Hello @mallman,
This is because
ColumnType
is a type dedicated to schema definition, not to schema introspection.ColumnType
provides ready-made constants for frequently used column types:.integer
,.text
,.boolean
, etc. But it is not an enum. It is a struct. SQLite accepts about everything as a column type. For example, consider those three columns:All of them are valid ways to declare columns that store booleans. 2 is original but quite OK; 3 is…