{"id":16175710,"url":"https://github.com/osiris-team/jsql-gen","last_synced_at":"2025-03-16T10:31:19.624Z","repository":{"id":39346427,"uuid":"504324252","full_name":"Osiris-Team/jSQL-Gen","owner":"Osiris-Team","description":"Java SQL (JDBC) code generator with GUI. Removes 100% of the boilerplate code + compile-safe SQL.","archived":false,"fork":false,"pushed_at":"2024-04-22T10:20:23.000Z","size":867,"stargazers_count":14,"open_issues_count":8,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T11:44:29.960Z","etag":null,"topics":["code-generation","compile-safe","database","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Osiris-Team.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-16T22:33:20.000Z","updated_at":"2024-05-03T12:07:05.896Z","dependencies_parsed_at":"2024-05-03T12:17:10.253Z","dependency_job_id":null,"html_url":"https://github.com/Osiris-Team/jSQL-Gen","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Osiris-Team%2FjSQL-Gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Osiris-Team%2FjSQL-Gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Osiris-Team%2FjSQL-Gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Osiris-Team%2FjSQL-Gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Osiris-Team","download_url":"https://codeload.github.com/Osiris-Team/jSQL-Gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221662733,"owners_count":16859737,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","compile-safe","database","sql"],"created_at":"2024-10-10T04:45:34.931Z","updated_at":"2025-03-16T10:31:19.613Z","avatar_url":"https://github.com/Osiris-Team.png","language":"Java","readme":"# jSQL-Gen\nJava SQL (JDBC) code generator with GUI. Removes 100% of the boilerplate code and makes\nit possible to use SQL databases without writing one line of SQL (compile-safe SQL).\n\n![image](https://github.com/user-attachments/assets/b52d2fca-74dd-436d-a6b1-e990e9f922ac)\n\n## Usage\n1. Install the latest [release](https://github.com/Osiris-Team/jSQL-Gen/releases/tag/latest). \n    - \u003cimg width=\"20\" src=\"https://img.icons8.com/?size=48\u0026id=M9BRw0RJZXKi\u0026format=png\"\u003e\u003c/img\u003e Windows: Download the .exe installer file (anti-virus might flag it since its not signed, upload to [virustotal.com](https://www.virustotal.com/) if you want certainty).\n    - \u003cimg width=\"20\" src=\"https://img.icons8.com/?size=48\u0026id=17842\u0026format=png\"\u003e\u003c/img\u003e\n    \u003cimg width=\"20\" src=\"https://img.icons8.com/?size=48\u0026id=uoRwwh0lz3Jp\u0026format=png\"\u003e\u003c/img\u003e Other platforms: Make sure you have [latest Java](https://www.oracle.com/java/technologies/downloads/)\n      installed, then download the large .jar file and double-click it (if that doesn't work, open a terminal and run `java -jar NAME.jar`).\n2. Create a database, tables and their columns via the GUI. \n3. Press `Generate Code` and add the code to your project.\n4. Open `Database.java`, fill in your database credentials, and run your app.\n\n\u003cp\u003e\n\u003csub\u003e\n*Select a project directory to directly generate the code in there.\n**Instead of inserting raw, readable credentials you can provide functions that fetch\nthose from a file. \n***Its expected that you have a database specific SQL driver in your projects like\n\u003ca href=\"https://github.com/mysql/mysql-connector-j\"\u003emysql-connector-j\u003c/a\u003e for example.\n\u003c/sub\u003e\n\u003c/p\u003e\n\n## Example\n\u003cp\u003e\u003cb\u003eI want to have a table named Person with the fields id, name and age. So I create it with the jSQL-Gen GUI and copy\nthe generated code into my project. Then I can do the following:\u003c/b\u003e\u003c/p\u003e\n\n![image](./img_1.png)\n\n```java\n// The first time you use Person, the database, Person table \n// and its columns (and missing columns) will be created if needed.\n\n// Inserting rows:\nPerson john = Person.create(\"John\", 34);\nPerson.add(john); // Or: john.add(); id gets automatically set after adding\nPerson.createAndAdd(\"John\", 34); // The shorter variant\n\n// Updating existing rows:\njohn.age = 36;\nPerson.update(john); // Or: john.update();\n\n// Getting rows:\nList\u003cPerson\u003e all = Person.get(); // Gets all rows.\nList\u003cPerson\u003e allNamedJohn = Person.whereName().is(\"John\").get(); // Gets all rows where the name equals \"John\"\nList\u003cPerson\u003e allNamedJohn2 = Person.get(\"WHERE name=?\", \"John\"); // Sames as above, but with regular SQL\n// Lazily get rows:\nPerson.getLazy(results -\u003e { // List with 1000 persons\n  // Executed once every 1000 persons until all data is retrieved\n}, totalCount -\u003e {\n  // Executed when finished\n}, 1000); // Limit for each request \n\n// Deleting rows:\nPerson.remove(john); // Or: john.remove();\nPerson.whereName().is(\"John\").remove(); // Removes all rows where the name equals \"John\"\n```\n\n## Overview\n\n### ⚡️ Low code ⚡️ Bug and SQL safety ⚡️ Powerful API\nFast development and prototyping due to 0% boilerplate and developer friendly API.\nCompile-/Typesafe SQL queries via WHERE class.\nExtensive utility methods, like fetching results lazily, DB reflection and much more (see \"Features\" for a complete list).\n\n#### How does it work?\nGenerates one class for each table.\nThe generated class contains static methods like get(), add(), update(), remove() etc. to interact with the table.\nEach instance/object of the class represents\none row and has public fields like obj.id obj.name etc. that can be changed.\n\n#### Why should I use this?\nIf you used the default JDBC API at least once you will know why.\nJust reading the \"Safety\" section below will already give you an idea.\n\n## Features\n\n### 🛡 Safety\n- Secured against SQL-Injection by using prepared statements.\n- Protection against timed out connections.\n- 0% boilerplate and simple code decreasing the risk for bugs.\n- (Optional) Helper WHERE class for generating simple and complex SQL queries, from compile-safe functions.\n- Safe removal of rows where references will be unset (set to -1) by default. Also provides removeRefs(...) to safely remove referenced rows.\nFor conveniece if removing all rows with refs should be the default you can set `Database.isRemoveRefs = true;`. References are created by naming your column like so: tableNameId.\n- Forcing ids for all tables and AUTO_INCREMENT ensuring support for databases that\ncommunicate with multiple clients/applications.\n\n### ⚡️ Performance\n- No runtime overhead for class generation (unlike other ORMs).\n- Cached connection pool ensures optimal performance on small and huge databases.\n  Besides that it provides protection against timed out connections.\n- (Optional) Cached results for ultra-fast data retrieval\n  (cache gets cleared after INSERT/UPDATE/DELETE operations and is\n  simply a map with SQL statements mapped to their results lists).\n\n### 🛠 Customization\n- Generated classes can be enhanced by adding your own custom code at the bottom of the class.\n- Name your tables/columns however you like since internally names are encapsulated in backticks.\n- You can add/rename/delete tables and columns (also change types/definitions) whenever you want,\nsince each time you press \"Generate Files\", change details between the current and last version are generated\n(if there were any) and via an additional table with\ntable metadata, jSQL-Gen keeps track of the actual tables' state/version. Keep in mind that manual changes\nto the database directly could result in issues.\n\n### 🗄 SQL \u0026 JDBC\n- The generated SQL code should be compatible with all types of SQL databases. However no promises are made except for MariaDB/MySQL. Open an issue if there are problems with your database software.\n- The generated Java (and JDBC) code does not require any third party libraries and should work with Java 8 or higher.\n- Supports all JDBC data types + some extras like enum. ![img.png](img.png)\n- `NULL` is not allowed, instead use the `DEFAULT ''` keyword or `-1` for null id references.\n- Supports DEFAULT for blobs. Example: `file BLOB DEFAULT ''`.\n- Supports SQL DEFAULT for `NOW(), CURDATE(), CURTIME()`.\n\n### ✴️ Other\n- Simple UI to design databases within minutes.\n- AI based database generation via ChatGPT by having a prompt like [this](AI_PROMPT.txt) and then importing the generated JSON.\n- Autosuggestions for field definitions.\n- Database structure/design as JSON file.\n- Easily use multiple databases in a single project.\n- (Optional) Supports generating Vaadin Flow Form to create/update/delete each object/row.\n- The Vaadin Flow form also supports references to other tables (your field must be named `\u003ctable\u003eId` for example `personId`), meaning it will create a ComboBox that displays the object/row as string instead of only the id\nwhich also contains all the rows of that table and allows the user to change it.\n- DB \"Reflection\", meaning you can loop through table names, their columns, definitions and\neven execute get/add/update/delete. Provided in the generated Database class.\n- If a project contains a table with more/newer changes, that database is replaced/updated in jSQL-Gen.\n- UI: \"Merge from projects\" button, which allows to import one or multiple databases from existing database_structure.json files, via recursive file search.\n\n### 🔴 Cons / Todo\nPRs for these issues are greatly appreciated (sorted from most important, to least important).\n- You need to know a bit of SQL, especially about definitions and defaults. This could be fixed by simplifying the GUI further.\n- Direct modifications of the database by a third-party program may make cache outdated (if cache enabled).\n- Java Code Generator: No \"direct\" support for `FOREIGN KEY` / references between tables, ref must contain word \"id\" in its name. However note that the idea of references is supported (columns named tableNameId are refs).\n- Java Code Generator: No support for `VIEW, JOIN, UNION` / merged tables/results. This might never get fixed if its not possible to create a developer-friendly / simple API for this.\n- Compile safety for enums, right now an enum is simply a string.\n- Better compile safety for type length limits, like `VARCHAR(200)` for example. Is this even doable?\n- Database might provide specific keywords/functions for frequently used defaults like `NOW()`, some of those are supported (meaning there is equivalent Java code for it),\nbut there are probably more that aren't.\n\n\n## Tipps\n- You can select a project directory to directly generate the code in there. The generated code/files can also be found in the `generated` folder (press `Show Data` on the first tab, to open the location).\n- Its possible to add additional Java code at the bottom of each generated class (only works when a project directory was selected).\n- Its recommended to name your tables like you name your regular\nJava objects, and your columns like your objects' fields.\n- You can rename/refactor generated Java classes and their fields/methods etc., but keep\nin mind that those changes won't affect the actual database tables/columns.\n- Thus changes to the database (specially changes in data types) should be made using the GUI.\n- When dealing with big amounts of data its recommended to use the WHERE class to its full extend to avoid going out of memory\nor use the lazy loading methods.\n- Make sure that all NOT NULL fields are on the upper half of the fields and the rest below. The generated functions will make more sense and will\nbe generally less error prone.\n- If you want a list of items as a field or mappings between tables, create a new table named something like `PersonAndOrder` add fields for personId and orderId, and optionally any additional fields that are relevant for that relation.\n\n\nLogos provided by [icons8.com](https://icons8.com/icons/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosiris-team%2Fjsql-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosiris-team%2Fjsql-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosiris-team%2Fjsql-gen/lists"}