The new MySQL 9.0 release has the capabilities to store JavaScript written programs

8th Jul 2024 | category: Software | Hits: 104 The new MySQL 9.0 release has the capabilities to store JavaScript written programs

This July 2024, when the MySQL Community announced the new releases of MySQL, was surely good news to all the developers but the Javascript community had more to dance for than others after learning that MySQL 9.0 Enterprise Edition will be able to directly support JavaScript stored programs.

Here are the take points:-

Point 1: A stored function

A stored function or stored procedure written in JavaScript is created, invoked, and maintained in much the same fashion as one written in SQL

Point 2: Declare with "LANGUAGE JAVASCRIPT"

The stored program language must be declared explicitly using LANGUAGE JAVASCRIPT in the CREATE FUNCTION or CREATE PROCEDURE statement used to create the stored program; otherwise, MySQL assumes the intended language is SQL.

Point 3: Demarcate using "AS" keyword

The program body must be demarcated using the AS keyword plus dollar-quoted delimiters such as $$, $js$, $mysql$, and so on. You must use the same delimiter to mark both the beginning and end of the routine body.

Point 4: No need for statement delimiter or terminator

It is not necessary to specify a statement delimiter or terminator as it is for SQL stored routines. If you employ the optional ; character to separate JavaScript statements, this is interpeted correctly as being part of the JavaScript routine, and not as an SQL statement delimiter.

Point 5: Don't USE JavaScript Reserved Words

Using a word that is reserved in JavaScript (such as var or function) as the name of an argument raises an error. Since MySQL JavaScript stored programs always use strict mode, this also includes keywords such as package and let.

Point 6: MySQL "ALTER" work incase you want to Edit JavaScript

You can modify a JavaScript stored program using ALTER FUNCTION and ALTER PROCEDURE as you would an SQL stored function or procedure. Changing the language using ALTER is not supported; in such cases, you must use DROP FUNCTION or DROP PROCEDURE as applicable, then re-create the stored program using the appopriate CREATE statement.