Screens: Code generation

Generating source code

NeoSQL feeds a table's column information into a template pack to produce source code such as entities, mappers and screens. It takes three steps: assign template packs to the project, refine the entity name and fields for each table, and review the result in the result window before installing or downloading it. Creating and editing template packs is explained in Template packs, and the variables and functions templates use in Template syntax.

Where you can use itWebDesktopWithout signing inSigned inLocal projectsAccount projects
FeatureEnvironment and workflow
Preview, download as ZIPAvailable on the web and desktop.
Install into a project folderSet a folder in the Project Configuration window's Location field in the desktop app.

Code generation works whether or not you are signed in, for either project type, and on every plan. Without signing in you can only choose public packs from the Store and packs on this device (Template store).

What's on the screen

No.NameDescription
1Preview table selectorShown only when you opened the window for several tables. Chooses which table the preview on the right shows. The template selection applies to all tables.
2Install Selected Templates buttonGenerates the checked templates for every selected table and writes them into the project folder. Available only on the desktop with the Location field set; otherwise hovering over the button shows why.
3Download Selected Templates buttonDownloads the same result as one ZIP file that keeps the folder structure of the install paths. Works on both the web and the desktop.
4Reapply Preview buttonRegenerates the result for the table being previewed. Press it after changing the entity settings in the table tab.
5Tag filterKeeps only the templates that have all the selected tags.
6Select All checkboxChecks or clears every template visible in the tree. The number on the right is how many of the visible templates are checked. Checks on templates hidden by the filter are left alone.
7Template treeEach pack assigned to the project is a bold row with its groups and templates under it. Click a template name to see its result on the right. An R mark means the template makes the installed file read-only, and an O mark means it overwrites an existing file.
8Install informationInstall Path, Alternative Path and whether it will Overwrite. The alternative path is where a template that does not overwrite writes when the file already exists.
9Result previewThe generated code. The Template source edit mode option is there only when you can edit that pack (see 'Editing the template source' below).
10Copy button, Install This Template buttonCopies the previewed result to the clipboard, or installs just this template for every selected table. The install button is on the desktop only.
  • When the window opens it generates only the first table. The other tables are generated when you pick them in the preview selector or when you install or download.
  • If a template fails while generating, a notification tells you which table, pack and template. The results of the other templates are still shown.

Preparation: assigning template packs

The packs a project uses are set in the Project settingsCode Generator tab. The tab is shown in local projects, and in account projects to the owner or to people with the All Permissions permission.

  1. Turn on the Enable Code-Generator switch in the Project settingsCode Generator tab. In a project that already has packs, the fields below show without the switch.
  2. On the desktop, use the Search ... button (1) to choose the project folder the generated code is installed into.
  3. Press the + Add Template Pack button (2) and press the Add button of the pack you want in the Store window (Template store).
  4. A pack tab (3) appears. If the pack asks for values, fill them in the Template Variables area (6).
  5. Press the Save button of the Project Configuration window.
  • The Location field (1) is required in desktop projects with code generation turned on. If it is empty, saving brings you back to this tab. On the web the field is greyed out and cannot be edited.
  • You must assign at least one pack to save. You can add the same pack more than once; each tab keeps its own variable values and per-table settings.
  • A mark such as v1 on the pack tab (3) is the pack version this project uses. It is fixed to the latest version at the time you add the pack and does not change on its own when the pack publishes a new version. When a newer version exists, the tab shows an arrow icon and the A newer version is available (v1 → v2). notice, and the Upgrade button moves it up. The × on the tab removes the pack from this project.
  • A pack whose name line (4) carries the live (my draft) mark is a pack you can edit. It uses your saved working copy rather than a version, so when you edit and save the pack, this project's results change right away. To share it with others, publish the pack (Template packs).
  • The Alias field (5) is a name for the pack used only in this project. It tells two copies of the same pack apart.
  • The Template Variables area (6) holds the global variables the pack defines (package name, paths and so on). Which fields appear depends on the pack, and you cannot save with a required field empty. A pack without variables shows the This template pack has no modules or variables to configure. notice.

Refining a table's entity settings

Once packs are assigned, the table tab gets a Code Generator tab (Table tab). The entity and field names are made once from the table and column names, and code is generated from the values you set here.

No.NameDescription
1ToolbarThe Generate Source Code... button opens the Generate Source Code - orders and 1 more window for this table. The Reset Entity Settings... button clears the entity settings and rebuilds them with the current rules. The Refresh button reads the current structure from the database again.
2Basic Settings areaValues shared by all packs: the entity's Name field, Alias field, Soft Delete switch and Description field.
3Per-pack Settings tabsOne tab for each pack assigned to the project. Sets the values that exist only for that pack's language.
4Entity areaThe entity-level settings the pack defines. Packs without any show the This pack's language profile declares no per-pack entity settings. notice.
5Fields gridOne row per column. The Database column group holds database values and cannot be edited. The NAME and COMMENT cells of the common column group are shared by all packs, and values such as the type and META in the pack-only column group on the right apply only to that pack.
6Gear icon on the NAME headerOpens the column naming rule window for this table only (Column Renamer). See 'Naming rules' below.
7Reset button at the end of a rowRebuilds the row's name with the rules and returns the common values and this pack's edits to their initial state.
  • Entity settings are saved with the Save button of the table tab. Unsaved changes show a dot next to the Code Generator tab name.
  • The initial value of the Alias field is the capital letters of the entity name joined and lowercased. For example, OrderItem becomes oi.
  • When you turn on the Soft Delete switch, you choose the deleted-flag column and the deleted-at column. Templates use these to generate code that marks rows instead of deleting them.
  • The settings of the Code Generator tab cannot be edited for a table marked for deletion.

Generating source code

  1. In the explorer, right-click a table and choose the Explorer context menuGenerate Source Code... menu. Select several tables and right-click to generate them together in one window. From the Code Generator tab of a table tab, open it with the Generate Source Code... button.
  2. Check the templates to generate in the tree on the left. Click a template name to see its result on the right.
  3. Check the result and the Install Path item. With several tables, switch tables with the Preview table selector.
  4. On the desktop, press the Install Selected Templates button. The files are written under the Location folder and the Source code installed. notification appears.
  5. On the web, or to get files instead, press the Download Selected Templates button. One table downloads table-name.zip; several download codegen-number-of-tables-tables.zip.
  • If the project has no packs assigned, the Explorer context menuGenerate Source Code... menu is greyed out.
  • Tables you have never expanded in the tree have their columns read from the database when the window opens. If the database cannot be reached, the Failed to load table metadata (columns). Please check the database connection. notification appears and the code is generated without columns.
  • If the tree is empty with the There are no templates to generate. Check that the pack has templates and that the pack version this project uses contains them. notice, the pack version the project uses has no templates. Check that the pack has been published.
  • If you install on the desktop with the Location field empty, the Please set the root path of the project where the source code will be installed. notice appears, and confirming opens the Project Configuration window.
  • An external AI can also create files with the same packs and settings through the MCP generate-code tool (AI and MCP, MCP tools).

What happens when you install

The template decides the install path, and the path is always resolved under the Location folder. A .. in the path cannot leave that folder, and a path starting with a drive letter is not installed. Each file is written according to the template's install settings.

A file at that pathTemplate settingWhat happens
Does not existCreates the folders and writes a new file
ExistsOverwrite (O)Overwrites it without asking
ExistsNo overwrite, alternative path setWrites to the alternative path
ExistsNo overwrite, no alternative pathSkips it
ExistsInsertion marker (needle)Replaces the marker text in the file with the result. Skips it if the marker is not there
  • A read-only (R) template makes the written file read-only. When it overwrites, it deletes the existing file and writes a new one.
  • If the template asks for git staging and the Location folder is a git repository, the written file is git add-ed.

Editing the template source

If you can edit the pack (a pack with the live (my draft) mark), the preview has the Template source edit mode option above it.

  1. Choose the Template source edit mode option and edit the template source.
  2. Press the Apply changes and switch to preview mode button. It is saved to the pack's working copy and the result is generated again.

This edits the pack itself. Results in your other projects that use this pack change too. Other people get the change only after you publish.

Naming rules (Renamer)

The initial entity and field names are made with the connection's naming rules. The rules are set in the Renamer tab of the connection window (Create and edit a connection). Rules are applied in order from the top.

No.NameDescription
1Restore Defaults buttonReturns both rule lists to their initial values. Asks first if rules exist.
2Table Renamer areaRules that turn a table name into an entity name. Choose regexp (replace a regular expression with replacement text) or case-format (change the letter case style) in the Renamer Type item, fill in the values and press the Add button.
3Rule listShown in the order they are applied. Use the arrow buttons to reorder and the trash button to delete.
4Column Renamer areaRules that turn a column name into a field name. Used the same way as for tables.
Initial ruleTable nameColumn name
1case-format CAMEL_UPPER (MyName)case-format CAMEL (myName)
  • The initial rules only change the letter case: order_item becomes OrderItem and customer_id becomes customerId. If your database puts a prefix such as tb_ before names, add a regexp rule (/^tb_/ → empty text) at the top.
  • Connections created earlier keep their saved rules. If the regexp /^[^_]*_/ rule that removes everything up to the first underscore is still there, a database without prefixes loses the first word and field names collide (order_id and customer_id both become id). Delete that rule or press the Restore Defaults button.
  • Changing the connection's rules does not rename entities already built. To apply the new rules, press the Reset Entity Settings... button of the table tab or the Reset button of a row.
  • To treat one table differently, open the Column Renamer window with the gear icon on the NAME header of the field grid. When that table has rules, they are used instead of the connection's column rules. The Load connection settings button copies the connection's rules, and the Save & Apply button saves and rebuilds every field name of this table, overwriting names you edited by hand.

Audit Table tab

The Project settingsAudit Table tab is in the settings of projects with code generation turned on, and is visible in local projects and to the owner of an account project or people with the All Permissions permission. It lets templates treat common audit fields such as Created by, Created Date, Modified by and Modified Date separately. Whether these values are used depends on the pack.

FieldContent
Audit TableThe table that holds the audit fields, chosen by connection, schema and table. If it is empty, the tab name shows a warning icon and the Some features may not work if Audit Table is not configured. notice
Audit Entity Interface, Immutable Audit Entity InterfaceClass names that entities with audit fields inherit from
Field Names For Creation, Field Names For ModificationNames treated as the author (Author) and date (Date) fields for creation and modification. Type a name and press the add button
  • Write field names after the naming rules (such as createdBy), not database column names.
  • The column information of the chosen table reaches templates only when you generate code for a table on the same connection.

Things to keep in mind

  • Installing writes files without asking. Overwrite (O) templates also overwrite files you edited by hand. Before the first install, download the result with the Download Selected Templates button to check it, or commit the Location folder to git.
  • Files are skipped when a template that does not overwrite meets an existing file or the insertion marker is not found. In that case, instead of the install-finished notification, a notification shows how many files were not installed and the first reason. If an error occurs while installing, the install stops and an error notification appears.
  • On the desktop, templates run on this device while generating code. Use public packs made by others only if you trust them, and read a pack you have not used before in Template packs first.
  • Private packs chosen while signed in cannot be read without signing in. A project that uses such a pack cannot generate code when opened without signing in.
  • Even when a newer version exists, results are generated from the pinned version. To use the pack author's changes, press the Upgrade button.