-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Engine (ROM) #334
New Engine (ROM) #334
Conversation
…lays won't affect the result
Is this change in the configuration API accidental? Before, the |
Also, when one generates a model before the backing sql table is created, the whole thing breaks because schema inferring fails. |
Okay, I tried HoundCI and it doesn't respect our |
@jodosha Looks like you forgot to add
|
@jodosha You might want to add the following to the
|
@beauby Sure, but why it doesn't report the issue locally and on Travis CI? |
Looking at rubocop's default config, it appears that by default, this cop is enabled or disabled depending on the TargetRubyVersion of rubocop which may be influenced by the environment in which it is ran, as it is not explicitly specified in the |
@beauby Thanks for the quick and detailed reply. I'm running rubocop 0.45.0 on MRI 2.3.1 and I didn't ran into that frozen string violation by running My point is: local machine and TravisCI agree, while HoundCI doesn't. The first two environments are more transparent for us than the latter. What I want to avoid is to have headaches like this in the future. |
@jodosha Agreed, but TBH, this seems like a shortcoming on rubocop's side, as the environment should not have any effect on static analysis of code. |
This was merged in master. Thank you all! 🎉 |
New Engine
Use
rom
as low-level engine forhanami-model
. Introduce new features (automapping for SQL databases, experimental associations), remove old (dirty tracking). Fix old bugs.Example
Before to dive into the details here's how it looks the basic example:
This reduces drastically the boilerplate to setup an entity and a repository pair.
Repositories
Keeping the good work from #299, repositories now expose their CRUD operations at the instance level, not at the class level.
Data (hashes) is the preferred input for CRUD operations. In past we used to pass entities, while this is still possible, it’s suggested to use just data.
Repositories can access all the relations with instance methods. For instance, from the
BookRepository
we can accessusers
relation (database table) with#users
.Repositories are able to auto infer the database schema and use the correct Ruby types. Advanced PostgreSQL types like UUID, Array, JSON(B) and Money are handled natively.
Repositories can also auto map database columns with entities attributes. In case there is a mismatch between the names, we can define a custom mapping. NOTE: manual mapping is optional and should be used only with legacy databases.
Custom queries can be defined with an intuitive Ruby syntax:
Entities
Entities are now immutable.
Automatic Schema
With SQL databases, entities get attributes from table schema.
As example, image to have a
users
table withid
(int),name
(string),email
(string),age
(int),created_at
(time), andupdated_at
(time).It ignores
foo
because it isn't part of the schema.age
instead isnil
because we haven't initialized it.There is also a new feature for entities which enforces schema types. When an entity is initialized with one or more wrong attributes it raises an error.
Custom Schema
If developers want to customize the set of attributes of an entity or specify the level of strictness of the type coercion, they can build a custom schema.
For a complete list of the options, please check: http://dry-rb.org/gems/dry-types/built-in-types/
Please note that
.attributes
changed its public API.Associations (experimental)
We introduced experimental support for associations (only
has_many
at this time).When we define an association, it does NOT add any method to the public interface. We can access the association internally via
#assoc
and define only the explicit operations that we need for our model domain.A special thanks goes to @solnic, @flash-gordon, @AMHOL and @timriley for ROM and their tireless support provided during these months of development. You rock! 💚
Closes #217
Closes #237
Closes #245
Closes #272
Closes #273
Closes #278
Closes #279
Closes #285
Closes #291
Closes #294
/cc @hanami/core-team @hanami/contributors