-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from harlanhaskins/master
Add fix for SQLite strings being coerced to numbers internally
- Loading branch information
Showing
3 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Fluent | ||
import SQLite | ||
|
||
/** | ||
SQLite-specific overrides for the GeneralSQLSerializer | ||
*/ | ||
public class SQLiteSerializer: GeneralSQLSerializer { | ||
/** | ||
Serializes a SQLite data type. | ||
*/ | ||
public override func sql(_ type: Schema.Field.DataType) -> String { | ||
// SQLite has a design where any data type that does not contain `TEXT`, | ||
// `CLOB`, or `CHAR` will be treated with `NUMERIC` affinity. | ||
// All SQLite `STRING` fields should instead be declared with `TEXT`. | ||
// More information: https://www.sqlite.org/datatype3.html | ||
if case .string(_) = type { | ||
return "TEXT" | ||
} | ||
return super.sql(type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters