Comments (1)
I added PostgreSQLEnumType
to make this a bit easier (see the commit referenced above).
As long as the enum is RawRepresentable
(backed by a string, int, etc) and the raw value is also a PostgreSQL-compatible type (all strings, integers, floats, bool, etc are) then implementation will be concise.
Here's what the models can look like:
enum PetType: Int, PostgreSQLEnumType {
static let keyString: TupleMap = (.cat, .dog)
case cat = 1
case dog = 2
}
struct Pet: PostgreSQLModel, Migration {
var id: Int?
var type: PetType
var name: String
}
Some example usage with expected return:
_ = try Pet(id: nil, type: .cat, name: "Ziz").save(on: conn).wait()
_ = try Pet(id: nil, type: .dog, name: "Spud").save(on: conn).wait()
let cats = try Pet.query(on: conn).filter(\.type == .cat).all().wait()
let dogs = try Pet.query(on: conn).filter(\.type == .dog).all().wait()
XCTAssertEqual(cats.count, 1)
XCTAssertEqual(cats.first?.name, "Ziz")
XCTAssertEqual(dogs.count, 1)
XCTAssertEqual(dogs.first?.name, "Spud")
Still trying to work out a way to make static let keyString: TupleMap
not required, but for now we must have knowledge of two distinct values for each nested type for Fluent to work properly.
Let me know if that looks good. Thanks!
from fluent-postgres-driver.
Related Issues (20)
- An `id` of `null` throws violates not-null constraint. HOT 1
- 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
- Aggregate SUM function fails 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.