Comments (8)
if its an Array, its returning a FakeSeq
from red.
Not a FakeSeq, but a ResultSeq
from red.
model Post {
has UInt $!author-id is referencing{ Person.id };
has Person @.author is relationship{ .author-id };
}
Post.author; # returns a Person::ResultSeq :of() an alias named author
Post.author.map( *.id ); # Seq of UInt
Post.all.grep: { .author.name eq “FCO” };
Post.new.author; # returns a Person::ResultSet
from red.
How can I know if I should continue on the ResultSeq chain or if I have to get the values and return a true Seq?
from red.
The of
of the ResultSeq
should define if its only creating the query or if it should run the query and iterate over the results
Person.all # returns an Person::ResultSeq (:of(Person))
.grep({ .name.starts-with("F") }) # adds an "WHERE name like 'F%'" on the query
# and return another Person::ResultSeq
.flatmap( *.posts ) # now it returns a Post::ResultSeq
# adding a join with the Person
.grep( *.title.chars == 5 ) # adds "WHERE LENGTH(title) = 5"
.map( *.body ) # returns an Red::Default::ResultSeq of Str
# Str doesn't Model, so the next call
# will run the query
.elems
;
SELECT
post.body
FROM
person JOIN post ON(post.author_id = person.id)
WHERE
person.name like 'F%'
AND
LENGTH(post.title) = 5
;
from red.
It's now possible to call the do-it
method on a ResultSeq
to return a DoneResultSeq
that will run the query on calling iterator
method
from red.
if you call .Seq
on a ResultSeq it will return a Seq that will run the query
from red.
but its automatic if you try to consume the seq
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.