Pondering Whether to Use Ponder? Here Are Three Reasons Why You Should.

Corey
4 min readJan 5, 2023

--

by Team Ponder

The time: 2:00am. The weather: stormy. The internet connection: shaky. The deadline: in a couple of hours. The task: connect to and optimize a SQL database. Many have encountered scenarios like the one described, but few have made their deadlines. If you’re pondering your survival strategy, think no more because Ponder is here!

Ponder, the newest ORM for Deno, is a simple tool that allows users to connect to their PostgreSQL database, create and manage tables, and introspect their database. If you want to dive right in, take a look at our documentation to get started. Otherwise read on!

Before going into the reasons why you should use Ponder, let’s talk about Deno. Deno is a Javascript runtime that boasts improved security, decentralized package management, and native Typescript support. While Deno has many awesome features, it lacks a standard object-relational mapping tool. Enter Ponder to fill the void.

Ponder makes connecting to your database easy.

Thanks to Deno’s decentralized package management system, just import Ponder from deno.land and you are good to go. We highly recommend importing the dotenv module as well and storing your database URI in the .env file for security reasons. Once you do, just invoke Ponder’s poolConnection() function to connect to your database and store the object it returns in a variable. You now have access to all Ponder functionality through that variable!

// Here is how to import Ponder!
import * as ponder from "https://deno.land/x/ponder/mod.ts";

// Import dotenv for security!
import "https://deno.land/x/dotenv/load.ts";

// Pull your protected URI from your .env
const DB_URI = Deno.env.get('DB_URI');

// Make connection to database and create instance of Ponder object
const db = await poolConnection(DB_URI);

Ponder makes creating and managing database tables easy.

With Ponder, users can create tables, drop one or more tables, create columns, drop columns, create rows, and delete rows by simply invoking the Ponder object methods. But Ponder’s functionality doesn’t stop there, users can also invoke methods to find tables, columns, rows, and cells.

// Invoking findAllinOne() will return all data from a table
const tableData = db.findAllinOne('person');

// Invoking findRow() returns all rows from a table meeting the criteria
const rowData = db.findRow('person', 'hair_color', 'brown');

// Invoke insertIntoTable(). A new row will be added to the people table
db.insertIntoTable('person',
['name', 'hair_color', 'eye_color'],
['Stella', 'green', 'purple']
);

//Invoke addColumns() to add columns and and their constraints to table
db.addColumns('programmers', {
id: ["SERIAL"],
howSmart: ["VARCHAR", "20", "NOT NULL"]
});

// ... And more!

Ponder allows users to introspect their databases.

Finally, Ponder allows developers to introspect their database. To introspect a database, create an introspection file in the project’s root directory. In that file, import Ponder from the URL. Then, developers should connect to the database and create an instance of the Ponder object. Once developers create an instance of the Ponder object, they can call the introspect method on it. When developers invoke the introspect function on the Ponder object for the first time, a new file, dataModels.ts, will appear in the root directory and be populated with models corresponding to the user’s database tables.

//import Ponder from URL
import * as ponder from "https://deno.land/x/ponder/mod.ts";

//make connection to database and create instance of Ponder object
const db = await poolConnection(DB_URI);

//invoke introspect function to create models of database tables
db.introspect();

The user can now instantiate instances of these models to manipulate tables and data using Javascript objects!

// Create an instance of the Model 
const newPerson = new person();

// Use dot notation to assign values to properties on new object.
// Properties must correspond to column names from table
// If types are incorrect error will be thrown.
newPerson.name = 'Sara';
newPerson.hair_color = 'dark brown';

// Invoke save() method.
newPerson.save();

// A new row containing the above values is added to the "person" table

Ponder Works Wonders.

The time: later-o-clock. The weather: still stormy. The internet connection: still shaky. The deadline: in fewer hours. The task: still connect to and optimize a SQL database. With Ponder, by your (code’s) side, the deadline seems more feasible. Ponder will help you code faster because it makes connecting to your database easy; makes creating and managing tables easy; and allows you to introspect your database. After reading about Ponder’s amazing benefits, become a Ponderer today!

Get involved!

Show us some support by heading over to our GitHub and giving us a star. Please don’t be shy about raising any issues or requesting features as well. We’re proud to be a part of the Open Source community so please feel free to fork, clone, and make pull requests if you would like to become a contributor to this project.

Connect with the team!

Sara Brown: GitHub | LinkedIn

Sam Goldenberg: GitHub | LinkedIn

Corey McClendon-Brown: GitHub | LinkedIn

Stella Baek: GitHub | LinkedIn

Matthew Connell: GitHub | LinkedIn

--

--