Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples of composing a complex query from simple ones #734

Open
nodejk opened this issue Sep 13, 2023 · 4 comments
Open

Add examples of composing a complex query from simple ones #734

nodejk opened this issue Sep 13, 2023 · 4 comments

Comments

@nodejk
Copy link

nodejk commented Sep 13, 2023

so, in order to realize large projects, we need a better pattern to do things in an concise way. here is an example to do so. i have more examples that i have worked with. let me know if this aligns with project goals = )

it's an example of consistent reusable query composition with inbuilt type-checking.

/*
Movie {
    id: uuid,
    name: str,
    reviews: Review[],
}

Review {
    id: uuid,
    author: Person,
    commentors: Person[],
}

Person {
    id: uuid,
    name: str,
}
*/


const query = e.select(e.Movie, (movie) => ({
    id: true,
    review_count: e.count(movie.reviews),
    reviewers: e.select(e.Review, (review) => review.author)
}))


const query2 = e.select(query, (q) => ({
    ...q["*"],
    where: e.op(q.review_count, ">", 10)
}))


const query3 = e.select(query2, (q) => ({
    reviewer_names: e.array_join(e.array_unpack(q.reviewers.author), ',')
}))


const response = query3.run(edgedbClient)

edit: it's only a fiddle that i jotted down in a editor to show how it can be done. actual methods to join select statements will be different in final example.

@scotttrinh
Copy link
Collaborator

Just so I understand, you're suggesting showing more examples of composing query objects with the query builder? I'm definitely for that! Seems like we can add some deep explanation to the existing Select docs, and a short example in the cheatsheet.

PRs welcome and you can find some information about contributing to the docs here. For JS docs, you don't need to go through the trouble of actually getting the whole edgedb/edgedb repo building the docs, but there are some helpful tips about our documentation style.

@nodejk
Copy link
Author

nodejk commented Sep 13, 2023

thanks for the swift response.

yeah, i wanted to contribute to more expressive examples. like making complex querying.

i will create examples of the query in the docs with full implementation link to my github repo. it will be great as many people will be able to read and fiddle with it.

lmk if that checks out!

also, it's my first time contribution to an open source project!

@scotttrinh
Copy link
Collaborator

i will create examples of the query in the docs with full implementation link to my github repo.

Cool. Instead of linking to your repo in the docs (we don't tend to link to any other projects aside from a few links to PostgreSQL), we can and should add your repo and any other more extensive examples to https://github.com/edgedb/awesome-edgedb

also, it's my first time contribution to an open source project!

🎉 Exciting!


For a concrete example of a good documentation PR, our head of developer relations @raddevon recently added some good documentation around explaining how to compose logical predicates (and, or, any, all) in #729

@scotttrinh scotttrinh changed the title better examples to show the utility of the client in large applications Add examples of composing a complex query from simple ones Sep 14, 2023
@nodejk
Copy link
Author

nodejk commented Sep 14, 2023

thanks, that checks out too!

Cool. Instead of linking to your repo in the docs (we don't tend to link to any other projects aside from a few links to PostgreSQL), we can and should add your repo and any other more extensive examples to https://github.com/edgedb/awesome-edgedb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants