title

text

Alexey Fadeev
Alexey Fadeev Sibedge
17:00 25 October
90 мин

Plv8 Framework: plv8 development in IDE with ES6, debugging, autotests and deployment

Many application developers prefer not to have logic on the DB side (in functions) as there are no suitable software development tools, especially for development teams. In the plv8 case, the situation worsens as this function contains both SQL and JavaScript code, and popular IDEs have no support for such a symbiosis. At this tutorial, I will introduce my development named "Plv8 Framework", which considerably simplifies the creation of code on plv8.

The gist is as follows: the JS code that is executed on the DB side can run on the developer's local computer by using node.js, which works on the same v8 interpreter. The plv8.execute special function is replaced by a function from the pg-native npm library, which calls the outer DBMS. I will demonstrate a set of tools chosen by me that enables the following:
- writing JS code in the IDE you prefer and enjoy syntax highlight;
- code debugging in real time (with breakpoint, watch, etc.);
- writing of auto-tests (unit-tests), with a variety of options: Postgres, SQLite, mocks;
- deploying your code in the DBMS;
- usage of additional npm packages (the issue is that all code of the plv8-based function should be included in the function's body, in one file).

You can use this tool regardless of the programming language that you use for the backend. However, it becomes more flexible if you use languages with static typing (like Java, C#, etc.). For the tasks where the backend is an intermediate layer between the frontend and DBMS, logic (or its part) can be placed in plv8/js with dynamic typing, which will simplify the development process.

In addition to the development of new functions on plv8, the framework provides a set of ready-made functions for CRUD operations. These functions are universal, they aren't tied to a certain database structure, and they can work in any project. If you use them, you can do less backend development, in some projects to a very significant extent.

The installation of the plv8 extension is the most complicated part of working with it. However, I have good news: my colleagues prepared Docker files and Docker images for PostgreSQL 13 with pre-installed plv8! So your start with plv8 will be super simple: you need to deploy the Docker container using just one command!
Docker file: PostgreSQL 13 + plv8 v2.13.15
Demo project for you to participate in the tutorial
For the tutorial, you need to install the following:
Node.js (the most desirable is LTS)
IDE for JS (i.e., free Visual Studio Code)
GraphQL Playground

Слайды

Fadeev-plv8framework.pptx

Видео

Видео доступно участникам мероприятия, выполнившим вход в личный кабинет

Другие доклады

  • Alexandra Kuznetsova
    Alexandra Kuznetsova Postgres Professional
    22 мин

    Mamonsu 3.0: New Features

    Mamonsu is an active monitoring agent for PostgreSQL based on Zabbix. Mamonsu 3.0 Major Update includes new metrics and more possibilities for data visualization via Zabbix screens. It also introduces the improved functionality of Mamonsu tools for interacting with the DBMS. In addition to the new functionality overview, I will also share the nuances of upgrading to the 3.0 version.

  • Ivan Frolkov
    Ivan Frolkov Postgres Professional
    45 мин

    Reliable implementation of complex business logic with pgpro_scheduler

    The pgpro_scheduler extension has an interesting but little-known feature - one-time jobs. Despite its simplicity, this feature can be used for complex transaction processing. On the one hand, it helps to reliably execute tasks taking a very long time, on the other hand, it ensures app scaling if certain conditions are met.

  • Igor Kosenkov
    Igor Kosenkov Postgres Professional
    45 мин

    Building a GEO-Cluster

    Everyone knows very well what a failover cluster PostgreSQL is and how such a cluster protects against failures within the same data center. However, recently, more and more enterprises have placed increased demands on their services, these requirements include disaster tolerance. We call such clusters a GEO-Cluster (KUK). In the report, I will talk about the varieties, principles and approaches to building GEO-Clusters PostgreSQL based on the Corosync/Pacemaker cluster software.

  • Petr Devyanin
    Petr Devyanin ГК Astra Linux
    45 мин

    How to ensure trust in system software using Astra Linux as an example

    The development of secure system software (like an operating system or a DBMS) and ensuring trust in it are complicated scientific and technical tasks. In our presentation, we will demonstrate how we resolved these tasks for the Astra Linux OS certified to comply with the highest security classes. We will discuss the key directions of our activities, from the formation of national standards to the development and verification of the formal access model, which is the basis for the attack surface protection mechanism on the OS's level. We will also share how we apply the methods and technologies of dynamic and static analysis of the program code and, finally, we will explain how we collect and analyze the data we get from analyzing the OS code. We will also discuss how to fix the code errors in the project with continuous integration.