question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In order to make the query API much more awesome, I would like to introduce the following interface to ceylon.language.meta.model:

shared interface Model<Parent,Result> 
        given Result<T> {

    shared Result<Type> get<Type>(Attribute<Parent,Type> attribute);

}

Then, we would change the typechecker so that any member expression like person.name where person is a Model<Person,Expression> would be desugared to:

person.get(`Person.name`)

(In the query API, I would declare From<T> to satisfy Model<T,Expression>.)

As a second phase, we can also figure out some way to support basic operators like ==, !=, <, >, <=, >=, &&, ||, !, +, -, *, / at the Model level.

There is one big problem with this otherwise-rather-simple proposal: the JVM backend doesn’t yet support type constructors, which is, AFAICT, essential to this proposal.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gavinkingcommented, Mar 26, 2017

An alternative syntax would be:

    value person = criteria.from(`Person`);
    value address = criteria.join(person.`address`);

    List<NameAndCity> results
            = criteria
                .where(
                    like(person.`name`, "Gavin%"),
                    address.`state` == literal("CA"))
                .orderBy(
                    asc(address.`zip`),
                    desc(person.`name`))
                .select(construct(`NameAndCity`,
                         with(address.`city`)
                        .with(person.`name`)))
                .getResults();
1reaction
gavinkingcommented, Mar 26, 2017

With this proposal, the following query:

    value person = criteria.from(`Person`);
    value address = person.join(`Person.address`);

    List<NameAndCity> results
            = criteria
                .where(
                    like(person.get(`Person.name`), "Gavin%"),
                    address.get(`Address.state`).equalTo("CA"))
                .orderBy(
                    asc(address.get(`Address.zip`)),
                    desc(person.get(`Person.name`)))
                .select(construct(`NameAndCity`,
                         with(address.get(`Address.city`))
                        .with(person.get(`Person.name`))))
                .getResults();

Would simplify to:

    value person = criteria.from(`Person`);
    value address = criteria.join(person.address);

    List<NameAndCity> results
            = criteria
                .where(
                    like(person.name, "Gavin%"),
                    address.state == literal("CA"))
                .orderBy(
                    asc(address.zip),
                    desc(person.name))
                .select(construct(`NameAndCity`,
                         with(address.city)
                        .with(person.name)))
                .getResults();

Which is much better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring MVC Model Interface - Javatpoint
In Spring MVC, the model works a container that contains the data of the application. Here, a data can be in any form...
Read more >
Spring MVC - Model Interface - GeeksforGeeks
Spring Framework provides an Interface called Model(I) to work with the data. It defines a placeholder for model attributes and is primarily ...
Read more >
Overview: Creating model interfaces - isee systems
A model interface allows your model's users to interact with the model by changing model inputs, running the simulation, and viewing its output....
Read more >
Model (Spring Framework 6.0.2 API)
Interface that defines a holder for model attributes. Primarily designed for adding attributes to the model. Allows for accessing the overall model as...
Read more >
Open Model Interface Provides Standard for Advanced SPICE ...
OMI allows circuit designers to simulate and analyze such important physical effects as self-heating and aging, and perform extended design optimizations. It is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found