MySQL and Postgresql as standalone apps
-
-
Fyi, what I have ended up doing is creating a custom cloudron app with the postgresql feature and then hosting a nodejs app that communicates directly with the database to alleviate the need for generic direct access to postgresql.
@Lanhild If you want direct access to a postgresql database for testing and DB analysis stuff then you can use a custom app with the postgresql feature enabled and girish's post here to connect pgadmin to that custom app's postgresql instance.
-
@ChristopherMag Thanks for the info!
Do you mind sharing your custom application code? I'm very interested in that.
-
@Lanhild I don't think I can share the full code but here is a relevant snippet if you wanted to get stated with using postgresql from within a nodejs cloudron app:
import Koa from 'koa' import cors from '@koa/cors' import Router from '@koa/router' import { koaBody } from 'koa-body' import postgres from 'postgres' var sql = postgres(process.env.CLOUDRON_POSTGRESQL_URL) let app = new Koa() let router = new Router() app.use(cors()); router.get('/',(ctx, next) => { ctx.body = "Health Check Success"; }) .get('/someurltogetdatafrom', async (ctx, next) => { ctx.body = JSON.stringify((await sql` select somePostgresqlFunction( SomeParameterName => ${ctx.request.query.someparameternamefromquerystringparameter}) as SomeName ; `)[0].somename) }) app .use(router.routes()) .use(router.allowedMethods()); app.listen(8234);
-
@ChristopherMag Thanks for sharing
I've made a very simple custom app to deploy a psql DB using the Cloudron addon @ https://github.com/Lanhild/postgresql-cloudron
-
@timconsidine Exactly, spin up the app, grep the environment variables for the DB credentials and connect to it
-
Definitely worth adding to the AppStore.
Not much additional maintenance associated with having it there. -
@Lanhild If you want to take this a step further an option I wanted to explore but am not sure whether it would work would be to use something like node-tcp-proxy as the application itself with 5432 as source and destination port such that someone could connect to the app's name on port 5432 and the app would proxy that tcp session back to the postgresql database on port 5432.
There might be issues with this as I cannot think of another app example on cloudron that uses tcp without http on top so there may be some proxy stuff being done by cloudron itself before the connection makes it to the app that prevents this from working but it was on my list of things to try at some point.
-
@Lanhild Fyi, for me long term I think implementing PostgREST as a cloudron app is what I will eventually be aiming for as for me I am focused on postgresql and this app would eliminate the need for any code maintained by me in the cloudron app and just have my code in postgresql itself with the app dynamically building rest endpoints based on the code in postgresql.
The tcp proxy solution if possible would be useful separately as it would allow us access to MySQL, Mongodb, Postgresql, Redis, etc. directly via proxying the respective cloudron app service.