Methods of connecting to a database
Tashmet is split into two main parts, the storage engine and the client. The client issues commands in the form of plain objects to the storage engine via a proxy interface. The storage engine can live in the same application or be connected to remotely through socket.
The basic use case for Tashmet is one where both the storage engine and client (Tashmet) is run in the same app. The storage engine exposes a proxy interface that we can make the connection through.
See the Hello world example for how this is set up.
A more advanced use case is when the storage engine runs in a different process, or even on a remote server. We can for instance have the Tashmet client run in a browser connecting to the server, thus bypassing the need for a more traditional rest-inteface approach.
This is currently an experimental feature that lacks the security necessary for production. Only use for developmental purposes.
In the following example we will create a server that listens for incoming connections on port 8080.
The blog posts are stored in content/posts
and we have set up a Nabu database configuration that defines our collection. In the next step, when we set up the client and access the database called content
this file will be read by the storage engine as per the peristentState
option we specified above.
In the client we establish a connection using the ServerProxy
then we are free to use the database as we normally would. Notice how we run an aggregation where markdown content is transformed to HTML. This operation is carried out in the storage engine on the server and the results are sent to the client. This means that if we run this in a browser the bundle size is quite small since it only contains the Tashmet client, while we still have all the power to do things like complex data transformations.