in reply to online database for desktop app

I guess this is not good practice.

Hi, you are right about that!

The reason web services in general are so popular is that HTTP is just a very efficient, time-tested way of handling stateless server-client communication, like SQL queries.

Adding the capability to your app to make HTTP requests is trivial -- I would use HTTP::Tiny which is in core Perl and has a very user-friendly interface.

To serve responses I would install a modern Perl web application. There are lots of super-lightweight ones including HTTP::Server::Simple, but I would recommend going with something a little more feature-rich so it can handle your database needs natively, along with logging, authentication, tx encryption (https), etc etc. My choice would be Dancer2, which I like in part because it is very pluggable, meaning you can run it very lightweight with very lightweight code. Not least of the useful features is Dancer2::Plugin::Database. Once you've configured your Dancer app with your database settings, you have access to the DB in your code via the database keyword, and can make simple queries with sugar methods like quick_select.

Here's an oversimplified and contrived use case. Suppose you are providing the daily closing stock prices for some market and you have the important data in a table called price. The user has to provide the stock symbol and the date for which the price is requested. Your app will make an HTTP request to your server using a URL like https://your-backend.com/GOOG/date/2018-11-05, and get a neat response of {"price":"1057.79"}.

The entire server code for that is:

use Dancer2; use Dancer2::Plugin::Database; set serializer => 'JSON'; get '/:stock/date/:date' => sub { database->quick_select('price', { stock => params->{stock}, date => params->{date}, }), }; dance;
... with something like this in the Dancer2 config file:
plugins: Database: driver: 'mysql' database: 'test' host: 'localhost' port: 3306 username: 'your_app_id' password: 's3kr1t' on_connect_do: ["SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'" + ] dbi_params: RaiseError: 1 AutoCommit: 1
It's pretty simple, and lots of help is available if you need it. It's always good practice to lay the foundation so that if you meet with success your path forward is smooth sailing.

Hope this helps!


The way forward always starts with a minimal test.