Reputation: 625
I am creating a web based database PG client. built using ruby with only rack.
I have this endpoint at /connection
. It need to be accessed with POST with connection string with json body. This is part of the code that handle the /connection
endpoint
class Connection
def call(req)
req_body = JSON.parse(req.body.read)
connection_string = req_body["connection_string"].to_s
connection = PG::Connection.new(connection_string)
Rack::Response.new
rescue PG::ConnectionBad
Rack::Response.new([], 400, {})
end
end
the code basically just make a connection using connection string come from request body. Then if connection got no error, just return OK, but if have error it return 400.
But i want to save this connection so i can use it to query in another endpoint. My idea is just to create a sqlite database and save this connection string and maybe a session_id. so every time the request come i just read it and do connection again and do query.
Is there any efficient way? that is not use sqlite
Thanks
Upvotes: 0
Views: 31