Skip to content

Support CREATE LIBRARY / DROP LIBRARY and the USING clause for stored programs #30

@kyleconroy

Description

@kyleconroy

Summary

MySQL 9.2 added a top-level LIBRARY schema object that holds reusable JavaScript code, plus a USING (lib_list) clause for CREATE FUNCTION / CREATE PROCEDURE to import library symbols. Marino does not parse any of this.

MySQL version

Introduced in MySQL 9.2.

Current state in marino

grep -in 'CreateLibrary\|create_library\|DROP LIBRARY' parser/parser.y parser/keywords.go returns no matches.

Example SQL

Create a library (depends on issue for LANGUAGE JAVASCRIPT support):

CREATE LIBRARY lib_demo LANGUAGE JAVASCRIPT AS $$
  export function inc(n) { return n + 1; }
$$;

IF NOT EXISTS and qualified name:

CREATE LIBRARY IF NOT EXISTS test.lib_demo LANGUAGE JAVASCRIPT AS $$
  export const PI = 3.14159;
$$;

Use a library from a function via USING:

CREATE FUNCTION js_inc(a INT) RETURNS INT
  LANGUAGE JAVASCRIPT
  DETERMINISTIC
  NO SQL
  USING (lib_demo)
  AS $$
    return lib_demo.inc(a);
  $$;

USING with multiple libraries and aliases:

CREATE PROCEDURE p_demo()
  LANGUAGE JAVASCRIPT
  USING (test.lib_demo AS d, other_lib)
  AS $$ /* ... */ $$;

Drop:

DROP LIBRARY lib_demo;
DROP LIBRARY IF EXISTS test.lib_demo;

Validation

CREATE LIBRARY ... LANGUAGE JAVASCRIPT AS $$ ... $$; and CREATE FUNCTION ... USING (lib_demo) ... both parse and run successfully against MySQL 9.2.0 Community.

Notes for the implementer

  • Add LIBRARY as a non-reserved keyword.
  • Add CreateLibraryStmt, DropLibraryStmt, and a Using []LibraryRef field on routine AST nodes.
  • Each LibraryRef is {schema?, name, alias?}.
  • INFORMATION_SCHEMA.LIBRARIES is added in 9.2; no parser work needed (it's a regular table reference) but may be worth a test.
  • Reference: https://dev.mysql.com/doc/refman/9.2/en/create-library.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions