DenoGres 2.0 Unleashed
DenoGres 2.0 is now live! Included in this version is a new suite of features built on top of DenoGres 1.0, granting developers more tools and reasons to work within DenoGres.
A user-friendly GUI, bidirectional database syncing, database seeding, and migration logging are but a handful of features included in DenoGres 2.0!
Today we are releasing the next iteration of DenoGres, version 2.0. Version 2.0 comes with a significant number of improvements to core functionality which make DenoGres not only easier to use but also a more comprehensive ORM solution linking PostgreSQL to the Deno runtime.
Highlights in this release include:
- Bi-directional synchronization of database/Model
- Database seeding
- A graphical query browser interface
- Database migration logging
Bi-directional database synchronization
One core feature implemented as a part of version 2.0 is the addition of bidirectional database synchronization. Upon invoking the command ‘ — db-pull’, DenoGres will create a model.ts file. This file represents the user’s database schema from PostgreSQL in TypeScript object form. Any changes that occur within PostgreSQL can be pulled into the user’s project directory by invoking ‘ — db-pull’, which will overwrite the current model file in DenoGres. Another piece of functionality that lives within this feature is the ability to sync changes to the PostgreSQL database schema through the ORM model (model.ts) in DenoGres. If a user wants to make changes to their PostgreSQL schema down the line, they can do so within their own IDE by modifying their model.ts file and invoking the command ‘ — db-sync’. Invoking ‘ — db-sync’ will then use the model.ts as its base and synchronize the PostgreSQL database schema to match the Models from the model.ts file.
Note! All database schema changes can be synced one by one, however, it is much more efficient to make all your changes at once and then sync those changes together.
Once changes have been made to the model, run the command ‘ — db-sync’ and all of the changes made to your model will be synced to your PostgreSQL database schema.
With our latest addition of database seeding, you can now insert test data into your PostgreSQL database directly through DenoGres! To get started, you’ll need to first create a file named seed.ts inside of the root directory. Next, create an array of objects, assigning it to a label matching the name of the table you want to create inside the PostgreSQL database. Within your newly created variable, each object within the array will represent a record (row) to be added to the PostgreSQL database.
Note: Make sure each of the data objects conforms to the schema as laid out in the model.ts file.
An example of a seed.ts file looks like this:
Now, all you need to do is run: denogres — db-seed
GUI Query Browser
Version 2.0 introduces a visual query browser that can be opened through the command line interface. Previously, all of DenoGres functionality had to be accessed by executing scripts, and users were confined to parsing through SQL data from within the command line. The query browser was designed to address such challenges and allows for a more streamlined, efficient workflow.
As a part of the GUI query browser release, two main sections have been introduced: the connections manager and the query explorer. Within the connections manager, users can create/update/delete database credentials that will be saved to their account. In connection manager, users are also able to connect to their selected database(s). Once the user has connected to a database, the GUI will redirect users to the query explorer.
In the query explorer, users can see the Model classes associated with a given database. They can also generate and run queries against their Models.
Database Migration Logging
DenoGres 1.0 lacked the ability to track or store database migrations. If a user opted to change the shape of their model and later decided against it a week later, there’d be no way for them to go back to their previous schema. DenoGres 2.0 solves this issue.
Prior to DenoGres 2.0, when a user enters the CLI command ‘ — db-pull,’ a single ORM model would be created based on their current PostgreSQL schema. If the user made changes to the data model and subsequently wanted to revert back to their original model, details about the original model would be permanently lost. Now, when a user pulls their database schema to their model.ts file, DenoGres automatically creates a backup of that model and stores it for later use.
With the addition of bidirectional database synchronization, whenever the command ‘ — db-sync’ is run, DenoGres will automatically create a backup of the ORM model after it has been synced. This allows the user to have a model to re-sync the shape of their PostgreSQL database schema if they need to revert back to any saved model at any point in time.
As support for DenoGres expands, the team hopes to implement the following changes with the next version of DenoGres:
- Further support for dbSync — eventually account for multiple associations and composite unique keys within the DenoGres model.
- New “Compare” command — display side-by-side differences between previous models (if any exist).
- Further updates to migrations log — Log will be visible within the GUI so that users can track/view/compare model versions.
- ERD-style diagrams — Will be generated within the GUI, so users can have a comprehensive view of their data model.
- Additional support for MySQL, SQL Server, etc.
To learn more about DenoGres visit https://denogres.deno.dev/