Which stems from PostgreSQLDatabase+QuerySupporting
Seeing as in the file PostgreSQLDatabase+QuerySupporting doesn't even exist anymore my guess is that this was fixed in a later version, but that version is still either in beta or RC?
Update 2
case ._insert:
var insert: PostgreSQLInsert = .insert(fluent.table)
var values: [PostgreSQLExpression] = []
fluent.values.forEach { row in
// filter out all `NULL` values, no need to insert them since
// they could override default values that we want to keep
switch row.value {
case ._literal(let literal):
switch literal {
case ._null: return
default: break
}
case ._bind(let bindValue):
// EXTREMELY HACKY CODE
switch (bindValue.value) {
case .encodable(let encodable):
if (row.key == "id" && Optional<Int>.self == type(of: encodable)) { return }
default: break
}
break
default: break
}
insert.columns.append(.column(nil, .identifier(row.key)))
values.append(row.value)
}
insert.values.append(values)
insert.upsert = fluent.upsert
insert.returning.append(.all)
query = .insert(insert)
The following extremely hacky code fixed the issue, however it is super hacky and obviously not production code. Is there a more permanent solution here?
Given the following
User
table schema:I get the following output when I create the table in terminal:
Running the following command in
psql
gives me the same error:However running the same command with
id
removed gives me a successful input:Now with the following
PostgreSQLModel
:When I run the following:
I get the same error as when I passed in
(null, ...)
above:This is my
Package.swift
:Solution
When you've specified a nullable
id
, such as:Fluent
should automatically pass a request of the following if theID
passed isnull
:Instead of:
Update
Tracking down the error it seems to stem from here:
Where the serialized query is:
Which stems from
PostgreSQLDatabase+QuerySupporting
Seeing as in the file
PostgreSQLDatabase+QuerySupporting
doesn't even exist anymore my guess is that this was fixed in a later version, but that version is still either in beta or RC?Update 2
The following extremely hacky code fixed the issue, however it is super hacky and obviously not production code. Is there a more permanent solution here?