Comments (2)
Transferring this to FluentKit since that's where the code would live for such a feature.
It should be possible to declare field defaults in Fluent 4, which could be an improvement to how we handle timestamps. Those types of properties could be made to only support reading. But, I'm not sure how write-once properties would work. If you need to be able to write the property ever (even if only once), then the property needs to be writable. There's not really a way to tell the compiler to only make it writable once.
To give some context, this is how setting a read only property w/ a default could work:
struct Planet: Model {
let id = Field<Int>("id")
let name = Field<String>("name")
let createdAt = ReadOnlyField<Date>("createdAt", default: .currentDate)
}
let planet: Row<Planet> // from DB
try planet.get(\.createdAt) // Date
try planet.set(\.createdAt, to: ...) // Compiler error, ambiguous use of `set`
I'm not sure I love that API though since it's within the realm of possibility that you might need to update the createdAt
field for whatever reason. It seems like it should be up to the developer whether to do that or not.
FWIW, ReadOnlyField
could be declared entirely in user code without needing any internal Fluent support.
from fluent-kit.
In "regular" Swift, there is a way to declare write-once properties: let
. My idea was similar; have a kind of property that doesn't expose a set
method, with the only place to set its value in an initializer or when decoding from a database result set. However, I now see that set
is (needs to, I guess) declared on the model itself, not on each individual field.
Explicit manual updates could still be done via a SQL UPDATE
command, but by avoiding a set
method we could avoid accidentally changing the corresponding property on the model and then calling save()
with that changed property — again, similar to how let
works.
from fluent-kit.
Related Issues (20)
- Optimisations introduced in 1.35.0 cause SQLQueryEncoder to crash HOT 8
- Operator function '~~' doesn't accept a ModelAlias in QueryBuilder's filter
- Scheme .references() and foreignKey() 's constraint naming strategies are not unified. HOT 4
- Casting database with custom logger to SQLDatabase always fails
- Generated queries have non-deterministic ordering of columns, which trash monitoring/logging/performance HOT 7
- Using `IDProperty` of type `Int64` fails to create a database generated value
- how to use? Is there a document here HOT 2
- Page<T> where T: Encodable does not seem to be allowed to be extendable HOT 1
- Document how to use the FluentBenchmarker tests
- [Docs] add "how to use the package standalone" to readme HOT 2
- Insert queries error when models have relations defined HOT 9
- Date filters fail when TimeStamp.format has un underlying value that isn't Date
- Fluent Postgres driver crashes getting sum and average aggregates
- 1.42.2 no longer supports multiple properties with the same field name HOT 1
- MySQL delete multiple-field index fails HOT 1
- Filtering with ~~ on enum collection does not work HOT 6
- Async functions within attach closure
- Aliases in select queries can cause fatal errors HOT 7
- Using Querybuilder with .field() or .fields() on models with optional relations crashes in SiblingsEagerLoader() HOT 1
- owner likely unsaved, attach within attach closure HOT 2
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-kit.