-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feature request: different sql dialects #38
Comments
Actually better to pass a sql_dialect argument when instantiating PyDBML. It can default to ansi or whatever you currently have |
Hi! Since you mentioned it, maybe it's time to rewrite this part of the project. I'd suggest to approach it this way: We remove Something like this: class PostgresqlRenderer:
def render(model: SQLObject) -> str:
...
class DatabricksRenderer:
def render(model: SQLObject) -> str:
... My only concern is that I probably won't be able to maintain any extra dialects apart from the default one due to very little free time I have right now. But since a detached renderer approach is so flexible, the custom renderers don't have to be part of the PyDBML package. You can release the BricksRenderer as a separate library, and anyone who needs it will just need to install it. What do you think? |
Yes that is a better approach. Very flexible. And yes I agree you don't want to bite off more than you can chew. It's best to keep pydbml super lightweight and I was actually starting to think along these lines after I mentioned it. Let me know how I can help. But happy to create a separate package for Databricks if you make these changes |
Alright, let's do that! I will create the base renderer and update the rest of the code to use it. Then I will add a section on the main description page with the renderers catalogue, where yours will be the first one : } I'll hope to start this week |
Nice, nice. I'm hoping to have lots of free time on it next week. Cheers |
@big-c-note it took a bit more time and effort than I anticipated 😅 I'll be addressing the other raised github issues in the upcoming few days, and then will make a release. You are welcome to look at the new renderer classes in the PR in the mean time |
This is awesome! I have gotten busy with another project, but I'll work on this as soon as I get a breather. Thank you so much |
New renderer classes are released in 1.1.0 🥳 |
You rock!! |
Thanks 😄 The idea is that you subclass a from pydbml.renderer.base import BaseRenderer
class MySQLRenderer(BaseRenderer):
model_renderers = {} (see default renderer as an example) And then you define the renderer functions for each model. The function should have one argument - the model you need to render, and it should return a rendered sql string for that model. Use the @MySQLRenderer.renderer_for(Column)
def render_column(model: Column) -> str:
# do the rendering and
# return the string (see default renderer for the column model). And that's basically it. Finally, to use your renderer class instead of the default one, you just supply it as an argument to the database: mydb = Database(sql_renderer=MySQLRenderer) |
Awesome. I'll keep an eye out for docs as well. Huge thanks to you again. This is really going to be cool for our project. It'll take me a minute to circle back, but this should play a big role in our model management software. Cheers |
@Vanderhoof I am still working on my changes locally to ensure they work for my use case, but wanted to run this by you to see if you would support this usecase. Happy to make any changes to tests or however you want to organize the code |
@big-c-note sorry, my github notifications are messed up. I missed your comment, although did approve your PR. I totally agree, this was the intended use, I just forgot to add it to the parser! |
Hello, First of all, thanks for creating/maintaining this package! I currently work with postgresql and running into weird syntax issues when parsing it via this package but not with the main cli from dbml. Seems like the main one auto-detects the dialect and maybe I'm missing something but I must of assumed this one was doing the same. I get around my need by using the main library which is in nodejs but I wrote some python tests to help me validate through my CT pipeline. I upgrade to the most recent ( Thanks again |
@ar-to Hi! |
Hey, thanks for the codebase.
I'm making use of it for a project where I need to convert dbml into databricks sql create table statements.
Do you want pydbml to produce arbitrary sql dialects?
If so I could make a contribution. Loosely thinking I could turn .sql into a dictionary and store different sql dialects that can be accessed via key like "ansi" or "databricks".
From what I can tell Databricks is severely lacking erd tooling. Plus being able to generate arbitrary sql dialect create table statements makes model management super portable via dbml and pydbml
Anyway, let me know and I can push this upstream
The text was updated successfully, but these errors were encountered: