-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Consolidate to four templates in this repository: one basic template for each ORM DBOS supports. - Also include two more complex sample apps whose source code is in https://github.com/dbos-inc/dbos-demo-apps, one using Express and one using Next.js. - Use Express in the `hello-knex` app so the programming guide can use it as a base. May move other templates to Express later. - Remove OpenAPI generation, as the feature was rarely used, redundant with many popular open-source OpenAPI generators, and increasingly difficult to maintain.
- Loading branch information
Showing
155 changed files
with
243 additions
and
4,204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# DBOS Hello with Drizzle | ||
|
||
This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Drizzle](https://docs.dbos.dev/typescript/tutorials/orms/using-drizzle). | ||
|
||
## Getting Started | ||
|
||
Run these commands to build your app, set up its database, then launch it: | ||
|
||
```bash | ||
npm run build | ||
npx dbos migrate | ||
npm run start | ||
``` | ||
|
||
To see that it's working, visit this URL in your browser: [`http://localhost:3000/`](http://localhost:3000/). | ||
|
||
Congratulations! You just launched a DBOS application. | ||
|
||
## Next Steps | ||
|
||
- To add more functionality to this application, modify `src/operations.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`. | ||
- For a detailed tutorial, check out the [programming guide](https://docs.dbos.dev/typescript/programming-guide). | ||
- To learn more about DBOS, take a look at [the documentation](https://docs.dbos.dev/) or [source code](https://github.com/dbos-inc/dbos-transact-ts). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"watch": ["src/"], | ||
"ext": "ts,json", | ||
"ignore": ["src/**/*.test.ts"], | ||
"exec": "npm run build && npm run start" | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...eate/templates/hello-drizzle/package.json → ...reate/templates/dbos-drizzle/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "dbos-hello-drizzle", | ||
"name": "dbos-drizzle", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"build": "tsc", | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# DBOS Hello | ||
|
||
This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Knex](https://docs.dbos.dev/typescript/tutorials/orms/using-knex). | ||
|
||
## Getting Started | ||
|
||
Run these commands to build your app, set up its database, then launch it: | ||
|
||
```bash | ||
npm run build | ||
npx dbos migrate | ||
npm run start | ||
``` | ||
|
||
To see that it's working, visit this URL in your browser: [`http://localhost:3000/`](http://localhost:3000/). | ||
|
||
Congratulations! You just launched a DBOS application. | ||
|
||
## Next Steps | ||
|
||
- To add more functionality to this application, modify `src/main.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`. | ||
- For a detailed tutorial, check out the [programming guide](https://docs.dbos.dev/typescript/programming-guide). | ||
- To learn more about DBOS, take a look at [the documentation](https://docs.dbos.dev/) or [source code](https://github.com/dbos-inc/dbos-transact-ts). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"watch": ["src/"], | ||
"ext": "ts,json", | ||
"ignore": ["src/**/*.test.ts"], | ||
"exec": "npm run build && npm run start" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Welcome to DBOS! | ||
|
||
// This is a sample "Hello" app built with DBOS and Knex. | ||
// It greets visitors and keeps track of how many times each visitor has been greeted. | ||
|
||
import express, { Request, Response } from 'express'; | ||
import { DBOS } from "@dbos-inc/dbos-sdk"; | ||
|
||
export interface dbos_hello { | ||
name: string; | ||
greet_count: number; | ||
} | ||
|
||
export class Hello { | ||
// This transaction uses DBOS and Knex to perform database operations. | ||
// It retrieves and increments the number of times a user has been greeted. | ||
@DBOS.transaction() | ||
static async helloTransaction(user: string) { | ||
const query = "INSERT INTO dbos_hello (name, greet_count) VALUES (?, 1) ON CONFLICT (name) DO UPDATE SET greet_count = dbos_hello.greet_count + 1 RETURNING greet_count;"; | ||
const { rows } = (await DBOS.knexClient.raw(query, [user])) as { rows: dbos_hello[] }; | ||
const greet_count = rows[0].greet_count; | ||
const greeting = `Hello, ${user}! You have been greeted ${greet_count} times.`; | ||
return makeHTML(greeting); | ||
} | ||
} | ||
|
||
// Let's create an HTML + CSS Readme for our app. | ||
function readme() { | ||
return makeHTML( | ||
`Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br> | ||
For example, visit <code class="bg-gray-100 px-1 rounded"><a href="/greeting/Mike" class="text-blue-600 hover:underline">/greeting/Mike</a></code><br> | ||
The counter increments with each page visit.` | ||
); | ||
} | ||
|
||
function makeHTML(message: string) { | ||
const page = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>DBOS Template App</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
</head> | ||
<body class="font-sans text-gray-800 p-6 max-w-2xl mx-auto"> | ||
<h1 class="text-3xl font-semibold mb-4">Welcome to DBOS!</h1> | ||
<p class="mt-8 mb-8">` + message + `</p> | ||
<p class="mb-2"> | ||
To learn how to run this app yourself, visit our | ||
<a href="https://docs.dbos.dev/quickstart?language=typescript" class="text-blue-600 hover:underline">Quickstart</a>. | ||
</p><p class="mb-2"> | ||
Then, to learn how to build crashproof apps, continue to our | ||
<a href="https://docs.dbos.dev/typescript/programming-guide" class="text-blue-600 hover:underline">Programming Guide</a>.<br> | ||
</p> | ||
</body> | ||
</html>`; | ||
return page; | ||
} | ||
|
||
// Let's create an HTTP server using Express.js | ||
export const app = express(); | ||
app.use(express.json()); | ||
|
||
// Serve the Readme from the root path | ||
app.get('/', (req: Request, res: Response) => { | ||
res.send(readme()); | ||
}); | ||
|
||
// Serve the transaction from the /greeting/:name path | ||
app.get('/greeting/:name', (req: Request, res: Response) => { | ||
const { name } = req.params; | ||
Hello.helloTransaction(name) | ||
.then(result => res.send(result)) | ||
.catch(error => { | ||
console.error(error); | ||
res.status(500).send('Internal Server Error'); | ||
}); | ||
}); | ||
|
||
// Finally, launch DBOS and start the server | ||
async function main() { | ||
await DBOS.launch({expressApp: app}); | ||
const PORT = 3000; | ||
const ENV = process.env.NODE_ENV || 'development'; | ||
|
||
app.listen(PORT, () => { | ||
console.log(`🚀 Server is running on http://localhost:${PORT}`); | ||
console.log(`🌟 Environment: ${ENV}`); | ||
}); | ||
} | ||
|
||
// Only start the server when this file is run directly from Node | ||
if (require.main === module) { | ||
main().catch(console.log); | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# DBOS Hello with Prisma | ||
|
||
This is a [DBOS app](https://docs.dbos.dev/) bootstrapped with `npx @dbos-inc/create` and using [Prisma](https://docs.dbos.dev/typescript/tutorials/orms/using-prisma). | ||
|
||
## Getting Started | ||
|
||
Run these commands to build your app, set up its database, then launch it: | ||
|
||
```bash | ||
npm run build | ||
npx dbos migrate | ||
npm run start | ||
``` | ||
|
||
To see that it's working, visit this URL in your browser: [`http://localhost:3000/`](http://localhost:3000/). | ||
|
||
Congratulations! You just launched a DBOS application. | ||
|
||
## Next Steps | ||
|
||
- To add more functionality to this application, modify `src/operations.ts`, then rebuild and restart it. Alternatively, `npm run dev` uses `nodemon` to automatically rebuild and restart the app when source files change, using instructions specified in `nodemon.json`. | ||
- For a detailed tutorial, check out the [programming guide](https://docs.dbos.dev/typescript/programming-guide). | ||
- To learn more about DBOS, take a look at [the documentation](https://docs.dbos.dev/) or [source code](https://github.com/dbos-inc/dbos-transact-ts). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.