Comments (6)
Having recently spent a week fighting hand and fist against SQLAlchemy to get it to just produce a union query with selects from subqueries with aggregate and window functions, that took me ten minutes to actually write by hand. You want to be able to go from SQL into language syntax thats like SQL, as well as language syntax thats idiomatic to whatever crazy rendered SQL that can get the job done. Personally I am a fan of the escape hatch abstraction. Something that's very thinly abstracting the SQL so you avoid vendor lock in, but close enough I can translate almost directly. Might not have to be related to the ORM really, just work relatively nicely with SQL generation in concert with the ORM. So perhaps a subquery is from an ORM expression, the other is some vendor specific directly optimised by hand query close to raw SQL, and the two are nicely combined to be rendered together with a parent query like object referencing either as if it was more ORM like.
from red.
WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
SELECT sub_part, part, quantity FROM parts WHERE part = 'our_product'
UNION ALL
SELECT p.sub_part, p.part, p.quantity
FROM included_parts pr, parts p
WHERE p.part = pr.sub_part
)
SELECT sub_part, SUM(quantity) as total_quantity
FROM included_parts
GROUP BY sub_part
I know, it’s not complete... and I don’t know if it is possible (yet). But the way I’m thinking of taking is something like:
(IncludedParts.where({ .part eq “our_product” }), { .^where: .part == IncludedParts.sub-part } ... *).classify: *.sub-part, :reduce-field{ .quantity.sum }
from red.
I think if we find a generic and composable way to represent each SQL feature it will be possible to create large and complex query.
So, I’ll put it here some thoughts about some of the “special” features you used on your example. Not all at once. And please comment every one you’d like to!
from red.
I don’t know if it is possible but the way I think to do something like this
WITH RECURSIVE t(n) AS (
VALUES (1)
UNION ALL
SELECT n+1 FROM t WHERE n < 100
)
SELECT sum(n) FROM t;
Is with something like this
(Red.select({ 1 }), * + 1 ... * < 100).sum
from red.
I was thinking about that and Im starting to disagree...
The way Im thinking now is that the Red user should be able to do with Red any thing it could with local data, what SQL would it generate isn't a problem. What do you guys think?
I mean: we should map language syntax
to sql
, and not sql
tho language syntax
...
from red.
I think Red is tracking a way to transform perl6 code to SQL, something like:https://github.com/FCO/Red/wiki/Better-map-grep and https://gist.github.com/FCO/87831dd190e1bb12adb138ce866acb73
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.