Comments (12)
I agree with the idea of creating a class that is a collection of models. How about we use 'Collection' as the name instead of 'Schema'? Especially since we may need to use that term somewhere else in the code.
Collections would work like this:
Collections and models in one file:
Collection AB {
model B is table<bbb> { ... }
model A is table<aaa> { has UInt $.id is serial; has B @.bs is relationship{ .a-id } }
model B { has UInt $.id is serial; has UInt $.a-id is referencing{ A.id }; has A $.a is relationship{ .a-id } }
has A $.a;
has B $.b;
}
Or in multiple files:
use Model1;
use Model2;
use Model3;
Collection AB {
has Model1 $.model1;
has Model2 $.model2;
has Model3 $.model3;
}
And objects can be versioned, ala:
use Model1:ver<0.1>;
use Model2:ver<1.3>;
use Model3:ver<1.0>;
Collection AB:ver<1.0> {
has Model1 $.model1;
has Model2 $.model2;
has Model3 $.model3;
}
from red.
How to create different models on different files? Because the way relationship works its verry probably that a model reffer another model and vice-versa
from red.
Its not needed any more, once you can create relationship that will be lazily evaluated.
from red.
The issue of getting two versions of the same Model or Collection to interoperate (migrations perhaps) is a critical issue that should be discussed if this is to be carried further.
from red.
what about collection
instead of Collection
?
from red.
Fine with me, but why the change in case?
from red.
model
is lowercase, class
is lowercase... I just think collection
in lowercase would be consistent...
from red.
I like the way @Xliff is thinking. Whether we say collection
or schema
is of no odds to me, but I think I would find it clearer if it were schema
. I don't see any reason why a model couldn't exist in more than one schema, after all.
In fact, I really like the idea of having a schema
that is simply a subset of all the models you have in your app. That way, different parts of the app can be given different scopes.
We could go as far as to say, if you are related to a model not in your schema, you can't use it (rather than trying to look for it).
from red.
I don't know that having different versions of the same model at the same time even makes sense. Taking a cue from DBIx::Class in Perl 5 land, the entire schema has a single version, since the status of all tables in the database determines whether or not they will work together.
The model classes that we create relate directly to a real-world table in a database somewhere. Only the matching versions of the models themselves are guaranteed to work with the corresponding table in the database. If we update a model and deploy the new table structure to an existing database, the old version of the model cannot (in the general case) work with this new table structure.
Ultimately, I don't think it makes any sense to support different versions of the same model in the same schema (or collection or whatever).
However, you could easily create a schema that contains an old version of the model and works on an old version of the database.
I propose the database handle be part of the instantiated schema object.
use MyApp::Schema::Model1;
use MyApp::Schema::Model2;
use MyApp::Schema::Model3;
use Red;
schema MyApp::Schema {
has Model1 $model1;
has Model2 $model2;
has Model3 $model3;
}
my $*RED-SCHEMA = MyApp::Schema.new: database => database "SQLite";
And then elsewhere, you can create a schema that is compatible with an outdated database:
use MyApp::Schema::Model1:ver<0.1>;
use MyApp::Schema::Model2;
use MyApp::Schema::Model3;
use Red;
schema MyApp::Schema {
has Model1 $model1;
has Model2 $model2;
has Model3 $model3;
}
# Probably export this or something
my $compatibility-schema = MyApp::Schema.new:
database => database( "SQLite", :database<outdated.db> );
from red.
The idea of using different versions would be to support migrations (#15)
from red.
Maybe schema should be a CompUnit::Repository?
from red.
Yeah it wouldn't be dissimilar to a plugin loader with some additional metadata.
from red.
Related Issues (20)
- Cannot find `pq` on Mac HOT 1
- Having issues while trying to modularise code HOT 9
- Totally broken on HEAD HOT 1
- How to pass creds for mysql db to Red tests? HOT 5
- Possible concurrency issue in query construction HOT 6
- Make docs use RETURNING HOT 1
- Failed to find dependencies: pq:ver<5>:from<native> HOT 1
- Add modularity HOT 2
- Error using Red. HOT 2
- Add support for "locking clause" on SELECT HOT 12
- Rakuize code and documentation HOT 2
- .year Method on PostgreSQL driver don't work HOT 5
- SparrowCI build fails HOT 1
- Regression in DateTime comparison operators on Pg HOT 7
- Unexpected behaviour of parameterised clause in `join-model` HOT 5
- Test fail: t/23-metamodel-model.rakutest line 62 HOT 7
- Tests fail on Rakudo v2024.03 HOT 13
- Implement SAVEPOINT (and friends.) HOT 3
- Make `.for-update`, `.skip-locked` a no-op on SQLite HOT 1
- EXISTS/NOT EXISTS as sub query 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 red.