Proposal: Type bound functions
- Dominant language
- Python
- Stars
- 38
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
With the advent of functions with insert/update/delete, it's very tempting to be able to define functions on types themselves.
Schema
```edgeql
type Movie {
title: str;
multi actors: Actor;
multi reviews: Review;
getWithRating: function() {
select Movie {
title,
actors: {
name
},
rating := math::mean(.reviews.score)
}
}
}
```
And then:
```edgeql
with m := (select Movie limit 1), select m.withRating()
```
I know it's possible to do a similar behavior by passing a movie as the first parameter. But it's extremely convenient this way. And it would enable moving more of the business logic to the database with a minimal cognitive overhead.
If a schema has 40 types and each type has 2-3 functions:
- Currently, a developer would have to browse through 80-120 functions to find one to use.
- But with this, he wouldn't have to think about it. Plus it would be possible to get autocomplete in queries and client libraries ...
I don't have any stats, but I don't think people define functions all that much either in Postgres nor other databases. Maybe because ORMs don't expose that in a nice way, or maybe they'd rather implement stuff in the programming language.
I think this would be aligned with EdgeDB because it enables offloading more to the database while preserving programming language ergonomics.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.