Coder Social home page Coder Social logo

map returning ResultSeq about red HOT 8 OPEN

FCO avatar FCO commented on July 24, 2024
map returning ResultSeq

from red.

Comments (8)

FCO avatar FCO commented on July 24, 2024

What SQL should it generate?

from red.

FCO avatar FCO commented on July 24, 2024
SELECT
   person.*,
   post.*
FROM
   person JOIN post ON(person.id = post.author_id)

from red.

FCO avatar FCO commented on July 24, 2024
SELECT
   person.*,
   array_agg(post.*)
FROM
   person JOIN post ON(person.id = post.author_id)
GROUP BY
   person.id, person.name, ...

from red.

FCO avatar FCO commented on July 24, 2024
SELECT
   array_agg(post.*)
FROM
   post
GROUP BY
   post.author_id

from red.

jonathanstowe avatar jonathanstowe commented on July 24, 2024

For some reason I was thinking about this last night and came to the conclusion that actually it might be of least surprise to the user if it actually did something like :

SELECT
   post.*
FROM
   person JOIN post ON(person.id = post.author_id)

And returns a ResultSeq of Post.

Which of itself is fairly useless, until you have a grep before the map such as:

Person.^all.grep( ?*.active).map({ .posts})

And get:

SELECT
   post.*
FROM
   person JOIN post ON(person.id = post.author_id)
WHERE
   person.active

But just my ยข2

from red.

FCO avatar FCO commented on July 24, 2024

O think that would be perfect for a .flatmap but I think it should return a Seq of Seqs...

Sent with GitHawk

from red.

FCO avatar FCO commented on July 24, 2024

I had this problem today:

use Red;
my $*RED-DB = database "SQLite";
#my $*RED-DB = database "SQLite", :database</Users/fernando/test.db>;

model MongerPM { ... }

model Monger {
    has Int $!id             is serial;
    has Str $.name           is column;

    has MongerPM @.monger-pm is relationship{ .monger-id }

    method pms { @!monger-pm.map: *.pm }
}

model PMGroup is table<pm_group> {
    has Str $.city           is id;

    has MongerPM @!monger-pm is relationship{ .pm-id }

    method mongers { @!monger-pm.map: *.monger }
    method gist { "{ $!city }.PM" }
}

model MongerPM is table<monger_pm> {
    has Int $.monger-id  is referencing{ Monger.id };
    has Str $.pm-id      is referencing{ PMGroup.city };

    has Monger  $.monger is relationship{ .monger-id };
    has PMGroup $.pm     is relationship{ .pm-id     };
}

#my $*RED-DEBUG = True;
Monger.^create-table;
PMGroup.^create-table;
MongerPM.^create-table;

my $*RED-DEBUG = True;

my $pm        = PMGroup.^create: :city<Rio>;
my $monger    = Monger.^create: :name<Fernando>;
MongerPM.^create: :$monger, :$pm;

#.monger-pm>>.pm.say for Monger.^all
#for Monger.^all -> $monger {
#    for $monger.monger-pm.map: *.pm {
#        .say
#    }
#}

.pms.say for Monger.^all

i think relationships of model type objects should continue returning the model, but it could mixin a role that would store what relationship it was, so, on translate it could use that...

multi method translate(Red::AST::Value $_ where .type ~~ Red::Model, $context?) {
    die "NYI: map returning a relationship";
}

from red.

FCO avatar FCO commented on July 24, 2024

Maybe we could use the same approach we did in #417 here.

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.