Comments (1)
I've done some more investigation on the matter and the issue can be solved multiple ways.
One would be to cast the type in the database already. For the query that means there must come some kind of cast parameter in the SQLExpression
. This in turn can then be read and inserted in SQLSerializer
which is called on line 13-14 of SQLDatabase
in the sql-kit
package. For postgres, the cast can be simply added in the query:
# SELECT SUM("scheme"."column"::<cast type>) FROM "table";
# For integer type, cast to integer is required.
SELECT SUM("scheme"."column"::integer) FROM "table";
For other databases, the implementation may vary, but this currently is only noticed on postgres, however, it may potentially be an issue for MySQL too.
Another option is to add the cast Type
to the .sum
function (and maybe any aggregate function) to enforce a certain cast on the later DatabaseOutput
decode step as shown below:
struct Start: Model, Codable {
...
@Field(key: "nr_of_planets")
var nrOfPlanets: Int
...
}
// For a specific double, this ignores the fact that the field is Int.
// This is a requirement for stored bigints in postgres.
Star.query(on: req.db).sum(\.$nrOfPlanets, as: Double.self).flatMap { doubleVal -> Int in
// Cast it manually
if let d = doubleVal { return Int(d) }
return -1
}
This issue is closely related to #92.
from fluent-postgres-driver.
Related Issues (20)
- updatedAt is incorrect after save HOT 2
- Accept URL string in configuration HOT 3
- Saving optional enum (nil) triggers: [ WARNING ] bind $3 type (UNKNOWN 0) does not match expected parameter type (TEXT) HOT 5
- 2.0.0 GM
- Type date but expression is of type text (transformAssignedExpr) HOT 5
- Migrations are now creating int8 fields as char in the DB and then the value gets messed up when querying HOT 1
- Sort by multiple field keys fail
- Postgres error thrown when using advised UUID ID field HOT 1
- [Feature request] Support JSONB column type for nested arrays / PostgreSQL
- simpleQuery flattens columns names to lower case HOT 1
- [Documentation] - We need thorough documentation on README or Wiki HOT 3
- Missing '#include <stdlib.h>'; 'abort' must be declared before it is used HOT 3
- debug logging no longer shows the RAW SQL HOT 4
- let user specify Postgres schema in the connection parameters. HOT 2
- Enum Migration: Adding multiple new cases to an already existing enum does only add the last case HOT 5
- No DEFERRABLE Constraint option
- DatabaseConfigurationFactory build error in 2.7.0 HOT 4
- Select SQL query for the fluent-postgres-driver with bindings
- PSQLError: Opening new connection for pool failed HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-postgres-driver.