Giter VIP home page Giter VIP logo

Comments (8)

FCO avatar FCO commented on June 2, 2024

if its an Array, its returning a FakeSeq

from red.

FCO avatar FCO commented on June 2, 2024

Not a FakeSeq, but a ResultSeq

from red.

FCO avatar FCO commented on June 2, 2024
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.

FCO avatar FCO commented on June 2, 2024

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.

FCO avatar FCO commented on June 2, 2024

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.

FCO avatar FCO commented on June 2, 2024

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.

FCO avatar FCO commented on June 2, 2024

if you call .Seq on a ResultSeq it will return a Seq that will run the query

from red.

FCO avatar FCO commented on June 2, 2024

but its automatic if you try to consume the seq

from red.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.