Cleanup examples (#16)

- Remove serverless example (it was basically dup of with-postgres)
- Add plugin (e.g. postgres) to example name
- Update all javascript examples and make sure they work
- Cleanup a bit of the ui in nextjs example
This commit is contained in:
Jake Runzer
2020-11-24 15:23:23 -07:00
committed by GitHub
parent fc0356d88c
commit 256cce952e
32 changed files with 321 additions and 684 deletions

View File

@@ -0,0 +1,13 @@
# Postgres Example
This example connects to a Postgres database with [node-pg](https://www.npmjs.com/package/pg).
## How to use
- Create a Railway project with the Postgres plugin
- Connect to your Railway project with `railway init`
- Run this example with `railway start`
## Notes
The SQL query being run simply fetches the current time in the database. It is located in `src/index.js`

View File

@@ -1,8 +1,18 @@
const pg = require("pg");
// Connect to the database using the DATABASE_URL environment
// variable injected by Railway
const pool = new pg.Pool();
(async () => {
const go = async () => {
// Query the database
const res = await pool.query("SELECT NOW()");
// Print the result
console.log(res.rows[0]);
// Close the database connection
pool.end();
})();
};
go();