2 min Devops

Support JavaScript in MySQL useful, but still risky

Support JavaScript in MySQL useful, but still risky

Oracle recently released a “JavaScript stored procedures” preview in MySQL 8.2. However, developers should be careful, as experts and Oracle point out.

The JavaScript stored procedures are executed by the GraalVM runtime, which supports both JavaScript and Java. These procedures allow developers to perform certain operations for data in the (MySQL) database themselves, such as formatting data with a template system such as Mustache, data extraction, complex validations, data compression and encoding, and transforming data.

Een diagram dat het proces van het ontwerpen van een database laat zien.

Other benefits of the new capability include allowing developers to become more productive because they can now write MySQL stored procedures in a familiar language, drawing from the full JavaScript ecosystem. Oracle said this also means that more developers can get involved, allowing companies to recruit developers from a larger pool.

Beware when using

Despite the benefits that JavaScript stored procedures in MySQL bring, critical developers warn of potential drawbacks in comments, such as on Reddit. They advise against mixing JavaScript and MySQL in the database engine because it can lead to confusion and introduce various problems that are difficult to solve.

According to critical developers, running code in stored procedures improves performance because the code runs as close to the data as possible. Still, at the same time, this code is less visible and, therefore, harder to access for troubleshooting and maintenance. This is not the case when the application code is kept separate from the database engine.

Oracle also cautious

Oracle itself also posts the necessary warnings. The tech giant indicates in accompanying documentation that the binaries should not be used in a production environment. Also, Oracle warns against using “global variables,” indicating that developers should be careful when using a familiar language in a different context.

The previewed JavaScript stored procedures in MySQL 8.2 are available only in the Enterprise edition of MySQL or in the MySQL Heatwave cloud service in the public cloud environments of AWS, Azure and Oracle Cloud Infrastructure (OCI).

Tip: JavaScript survey find React satisfaction low amongst developers