// Welcome to DBOS!
// This is the Quickstart TypeORM template app. It greets visitors, counting how many total greetings were made.
// To learn how to run this app, visit the TypeORM tutorial: https://docs.dbos.dev/tutorials/using-typeorm
import express, { Request, Response } from 'express';
import { DBOS } from '@dbos-inc/dbos-sdk';
import { DBOSHello } from '../entities/DBOSHello';
import { TypeOrmDataSource } from '@dbos-inc/typeorm-datasource';
const config = {
connectionString:
process.env.DBOS_DATABASE_URL ||
`postgresql://${process.env.PGUSER || 'postgres'}:${process.env.PGPASSWORD || 'dbos'}@${process.env.PGHOST || 'localhost'}:${process.env.PGPORT || '5432'}/${process.env.PGDATABASE || 'dbos_typeorm'}`,
};
const dataSource = TypeOrmDataSource.createFromConfig('app-db', config, [DBOSHello]);
export class Hello {
// This transaction uses DBOS and TypeORM to perform database operations.
@dataSource.transaction()
static async helloTransaction(name: string) {
const greeting = `Hello, ${name}!`;
let entity = new DBOSHello();
entity.greeting = greeting;
entity = await dataSource.entityManager.save(entity);
const greeting_note = `Greeting ${entity.greeting_id}: ${greeting}`;
return makeHTML(greeting_note);
}
}
// Let's create an HTML + CSS Readme for our app.
function readme() {
return makeHTML(
`Visit the route /greeting/{name} to be greeted!
For example, visit /greeting/Mike
The counter increments with each page visit.`,
);
}
function makeHTML(message: string) {
const page =
`
` + message + `
To learn how to run this app yourself, visit our Quickstart.
Then, to learn how to build crashproof apps, continue to our
Programming Guide.