Generate simple classes from database objects in DataGrip
DataGrip lets you run scripts against the selected schema objects. For example, you can generate Java classes from tables or, if you want, classes in any other language: C#, Python, etc. You can alter or extend the default functionality, for instance, generate an HTML or Markdown report.
Out of the box, DataGrip can generate Java classes. To do this, go to the context menu of a table (or several tables) and press Scripted Extension → Generate POJO.groovy.
Choose a destination folder, and that’s it! The class-file is ready.
Generate POJO.groovy is just a script written in Groovy. It means that you can modify it and create a new script based on it, for example, for generating classes for other languages. From the same context menu, click on Go to scripts directory to see where this file is placed.
You can edit the existing one or create new scripts. Just place your new script into this folder, and it’ll be available from the context menu.
Some examples from our users:
— Improvement of default script: comment support and replacing underscores in names.
— POJO Generators for Entity
— Generator of classes for Kotlin Squash
— Export structure as markdown into the clipboard
Before we also had Clojure engine and some people used it for scripting. For instance, here is the script for generating C# classes. If you strongly wish to use Clojure for scripting, please download Clojure runtime and scripting engine files here and place them in the lib folder inside the installed DataGrip folder.
We hope this post helps, feel free to ask questions if any.
Subscribe to Blog updates
Thanks, we've got you!
Introspection Level Auto-Selection
Back in 2015, I was the only DataGrip team member working on database introspectors. Since then, several of my teammates have followed suit with their own introspectors for various database management systems (DBMSs). The Oracle introspector, however, remains solely my project. The Oracle introsp…
Nextсloud Performance Hacks with EverSQL and DataGrip
Hi, I'm Pasha. In my everyday life, I'm a Developer Advocate for data engineering, but by night, I'm a geek. Like, a really geeky geek! I have used Linux since 2009 as my primary OS (BTW I use Arch). If possible, I always prefer to host everything I use. So if you decide to drop me an email at me@as…
Not All Databases/Schemas Are Displayed by Default. Why?
There is one thing which makes DataGrip different from many other database tools: DataGrip doesn't show all schemas and databases by default in the database explorer. In this post we'll briefly describe why it's designed like this and what you can do if this doesn’t suit your workflow. The most i…
Top 10 DataGrip shortcuts to empower your coding
We love shortcuts. They make coding faster and more efficient. But they are not always easy to remember. With that in mind, we’ve put together a list of our top-10 most useful DataGrip shortcuts. Execute statement: Cmd/Ctrl+Enter Click the statement or select the fragment of code that you want…