Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielrearden/sqlmancer
Conjure SQL from GraphQL queries 🧙🔮✨
https://github.com/danielrearden/sqlmancer
graphql graphql-js nodejs postgresql sql
Last synced: about 1 month ago
JSON representation
Conjure SQL from GraphQL queries 🧙🔮✨
- Host: GitHub
- URL: https://github.com/danielrearden/sqlmancer
- Owner: danielrearden
- License: mit
- Created: 2020-04-14T00:46:19.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-23T10:35:03.000Z (almost 2 years ago)
- Last Synced: 2024-11-09T19:22:26.770Z (about 2 months ago)
- Topics: graphql, graphql-js, nodejs, postgresql, sql
- Language: TypeScript
- Homepage: https://sqlmancer.netlify.com
- Size: 1.95 MB
- Stars: 139
- Watchers: 3
- Forks: 7
- Open Issues: 54
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - sqlmancer
README
# Sqlmancer
### Conjure SQL from your GraphQL queries 🧙🔮✨
![GitHub package.json version](https://img.shields.io/github/package-json/v/danielrearden/sqlmancer) ![GitHub](https://img.shields.io/github/license/danielrearden/sqlmancer) [![Build Status](https://img.shields.io/travis/com/danielrearden/sqlmancer?logo=travis)](https://travis-ci.com/danielrearden/sqlmancer) [![Coverage Status](https://img.shields.io/coveralls/github/danielrearden/sqlmancer?logo=coveralls)](https://coveralls.io/github/danielrearden/sqlmancer?branch=master) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/danielrearden/sqlmancer)](https://lgtm.com/projects/g/danielrearden/sqlmancer/context:javascript) ![Discord](https://img.shields.io/discord/625400653321076807)
> ⚠️ **This project is currently on hiatus.** I am hoping to resume working on Sqlmancer once I have some more free time. Feel free to submit new issues for feature requests or bug reports, although I may not address them immediately.
Sqlmancer is a Node.js library for integrating SQL with GraphQL. It empowers you to effortlessly and efficiently translate GraphQL queries into SQL statements.
## How it works
Sqlmancer generates a fluent, type-safe database client from your schema based on metadata you provide through schema directives. With Sqlmancer, your resolver can be as simple as this:
```js
function resolve (root, args, ctx, info) {
return Film.findMany().resolveInfo(info).execute();
}
```while still allowing complex queries like this:
Show query
```graphql
query FilmQuery {
films(
where: {
or: [
{ budget: { greaterThanOrEqual: 50000000 } },
{ language: { name: { in: ["Spanish", "French"] } } },
]
actors: { count: { lessThan: 50 } },
},
orderBy: [{
actors: { avg: { popularity: DESC } }
}],
limit: 100
) {
id
title
actors(
orderBy: [{
popularity: DESC
}],
limit: 10
) {
id
firstName
lastName
films(
orderBy: [{
films: { min: { budget: ASC } }
}]
limit: 5
) {
id
title
}
}
}
}
```## Features
* **Multiple dialect support.** Sqlmancer supports Postgres, MySQL, MariaDB and SQLite, enabling you to incorporate it into existing projects regardless of what flavor of SQL you're using.
* **Robust filtering and sorting.** Add complex filtering and sorting to your queries, including filtering using logical operators and filtering and sorting by fields and aggregate fields of related models.
* **Arbitrarily deep nesting.** Define one-to-one, one-to-many and many-to-many relationships between models. Related models can be filtered, sorted and paginated just like root-level fields.
* **Performance.** Avoid the N+1 problem by building a single SQL query to fetch all necessary data, regardless of query depth.
* **Mutations made easy.** Create, update and delete records, with or without transactions, using a simple, fluent API. Easily provide WHERE, ORDER BY and LIMIT clauses to your queries when updating and deleting records.
* **Views and CTEs.** Take advantage of existing views in your database and create inline ones using common table expressions.
* **Custom scalars.** Use the scalars that make sense for your schema.
* **Abstract types.** Utilize unions and interfaces in your schema using views or single table inheritance.## Design goals
* **Annotation over transformation.** Sqlmancer aims to be as aspect-oriented as possible, with directives being used mostly to annotate your schema rather than outright change its behavior.
* **Limited type-generation.** Sqlmancer offers a number of convenient directives to generate arguments or types, but these directives are never required for Sqlmancer to work its magic. What types are exposed in the schema is ultimately left up to you.
* **More than just CRUD.** Sqlmancer empowers you to create the queries and mutations that are right for your schema.
* **Flexible and unopinionated.** Sqlmancer enabled you to easily add features like authorization, tracing, cost analysis and depth limits using existing libraries without paying for a "pro" version.See [the official documentation](https://sqlmancer.netlify.app/) for API reference, guides and more.
## Community
If you found a bug, have a feature request or want to contribute to the project, please open an issue. If you need help or have a question, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/sqlmancer) or come chat with us on [Discord](https://discord.com/channels/625400653321076807/710279654140805230)!
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Daniel Rearden
💻 📖 🤔
Pavel Ravits
📖
Tadej Stanic
🐛
Tristan Siegel
💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!