Ponder is an ORM for PostGres using the Deno runtime. It eliminates the need for developers to spend valuable time writing complex SQL queries.
import * as ponder from "https://deno.land/x/ponder/";
To include Ponder in your next project, add this dependency:
import * as ponder from "https://deno.land/x/ponder/mod.ts";
You'll now be able to connect Ponder to your Database. First, store your Database URI in your .env file. Then pull it into your working file and store it.
const DB_URI = Deno.env.get('DB_URI');
You can connect to your DB using the built-in poolConnection method:
const ponderDB1 = await ponder.poolConnection(DB_URI);
Now you are now able to run any of the built in functions off the ponderDB1 variable:
const inserted = await ponderDB1.insertIntoTable('people', ['name', 'hair_color'], ['Corey', 'red-brown']);
A more in-depth Getting Started guide is available in the docs.
Create a new instance of poolConnection passing in the database connection string. By default, the number of pool connections is set to three and lazy loading is enabled. Users may also specify the number of server connections and whether the loading type is lazy.
import { poolConnection } from'./deps.ts
const ponder = new poolConnection('PG_URI')
const ponder = new poolConnection('PG_URI', 5, false)
const data = await ponder.findAllinOne('people');
const data = await ponder.findColumn('age', 'people');
const data = await ponder.findRow('people', 'hair', 'brown');
ponder.findCell('people', 'name', 'corey');
ponder.insertIntoTable('people', ['name', 'hair'], ['Sam', 'red']);
ponder.updateTable(people, [hair_color, eye_color], ['blonde', 'hazel'], [name, birth_year], ['Anton', '1860'], 'or');
ponder.deleteRow(hair_color, ['blonde', 'pink'], ['Clementine']);
ponder.createTable('Cats', { id: ["SERIAL"] areCute: ["VARCHAR", "20", "NOT NULL"] });
ponder.dropOneTable('Cats', true);
ponder.dropMultipleTables(['Cats', 'People'], true);
ponder.addColumns('programmers', { id: ["SERIAL"] howSmart: ["VARCHAR", "20", "NOT NULL"] });
ponder.dropColumns('programmers', columnsToDrop: {howSmart: true});
Ponder provides an introspect method to receive JavaScript representations of the data in your SQL Table. Because running the introspect method will create/write a new file in your file system, it is recommended to create a new file in your project root directory. Run this file using deno run to execute introspection. (If you keep your instrospect execution within another file, it may run repeated on the same database and will write unnecessary duplicates in your file system).
After importing ponder from your deps.ts file or from ponder directly, you'll need to first connect your database. After making a connection, all you need to do is invoke instrospect function:
ponder.introspect();
import { Model } from './deps.ts' export class person extends Model { tableName = 'person' static person_id = { data_type: 'integer', is_nullable: 'NO', } static name = { data_type: 'character varying', is_nullable: 'YES', } static hair_color = { data_type: 'character varying', is_nullable: 'YES', } static age = { data_type: 'integer', is_nullable: 'YES', } }
export interface person { name: string; hair_color: string; age: number; height: number; favorite_movie: string; favorite_book: string; }
const newPerson = new person();
newPerson.name = 'Sara'; newPerson.hair_color = 'dark brown';
newPerson.save();
newPerson.name = 'Johannes'; newPerson.hair_color = 'black'; newPerson.age = 22; //Invoking update function makes these changes in database newPerson.update();
newPerson.search();
newPerson.delete()
Currently under development!
Coming Soon! A feature for the future!
To make contributions, create a fork of the dev branch. Please be sure to utilize the Deno Typescript linter. Ensure that any changes made are reflected in the documentation. Make a pull request to the Dev branch when you have finished making your changes, note that once submitted any changes made will be covered under the MIT license. Feel free to contact the maintainers with any questions or concerns.