Slide 1

Slide 1 text

JavaScript, in the Oracle Database ?? Is that even a real programming language? Jeff Smith Distinguished Product Manager Oracle Database Tools

Slide 2

Slide 2 text

• product manager • @Oracle since 2012 • database tools • GUIs, CLIs, Web Apps, & REST APIs whoami 2

Slide 3

Slide 3 text

Copyright © 2023, Oracle and/or its affiliates 3 Martin Bach Loic Lefevre Lucas Victor Braun MLE JS Database PM Developer Relations PM Oracle Research GraalVM Dev Lead @martinDBA @Loic__Lefevre @lucasbraun87 MUST FOLLOWS for MLE JS in Oracle Database 21-23c

Slide 4

Slide 4 text

Copyright © 2023, Oracle and/or its affiliates 4 The Oracle Database adds support for ‘JavaScript snippets’ to be executed. The JavaScript is powered by the GraalVM GraalVM provides an ECMAScript-compliant runtime to execute JavaScript and Node.js applications. The Multilingual Engine, or MLE. Our story starts in 21c

Slide 5

Slide 5 text

Copyright © 2023, Oracle and/or its affiliates 5 Why should we care about JS and the Oracle Database? MLE JS means these popular libraries are available in YOUR Oracle Database! • Request/Fetch • Validator (9m+ weekly downloads!) • Moccha • Mustache

Slide 6

Slide 6 text

Copyright © 2023, Oracle and/or its affiliates 6 DBMS_MLE: PL/SQL package for evaluating JavaScript in your Oracle database session How does it work? console.log DBMS_OUTPUT oracle.db module execute(sql)

Slide 7

Slide 7 text

Copyright © 2023, Oracle and/or its affiliates 7 PRIVS Required SQL> grant EXECUTE ON javascript TO hr; Grant succeeded. SQL> grant EXECUTE dynamic mle TO hr; Grant succeeded.

Slide 8

Slide 8 text

Copyright © 2023, Oracle and/or its affiliates 8 Using MLE JS in Oracle SQL Developer Web Oracle Database 21c & JS Snippets SQL Worksheet Code your ANON block with DBMS_MLE – wrap JS with q’~ … ~’; Execute as Script

Slide 9

Slide 9 text

Copyright © 2023, Oracle and/or its affiliates 9 MLE JavaScript support in SQL Developer Web 21c: Snippets & DBMS_MLE Code Editor Open a new JavaScript editor Write and Run your JS Get JS Editor Intellisense

Slide 10

Slide 10 text

Copyright © 2023, Oracle and/or its affiliates 10 MLE JavaScript support in SQL Developer Web 21c: Snippets & DBMS_MLE Code Editor SQL Developer auto-magically wraps the JS with the required DBMS_MLE bits

Slide 11

Slide 11 text

Oracle Database 23c Oracle Database 23c accelerates Oracle’s mission to make it simple to develop and run all data-driven apps App Simple Copyright © 2023, Oracle and/or its affiliates 300+ New Features Now Available! Production: OCI Base Database, EE Free Download & Use: 23c Free

Slide 12

Slide 12 text

Copyright © 2023, Oracle and/or its affiliates 12 In addition to Snippets, you now can save your JavaScript libraries into the database. MODULES: “unit of MLE's language code stored in the database as a schema object” ENVIRONMENTS: define the runtime with directives, configuration scripts and provides name resolution of module imports CALL SPECIFICATIONS: PL/SQL program where the body is replaced with reference to JS module and function 23c Brings MODULES

Slide 13

Slide 13 text

Copyright © 2023, Oracle and/or its affiliates 13 Included in the 23c database distribution are: We include some powerful modules to help you gets started, Day 0! https://oracle-samples.github.io/mle-modules/

Slide 14

Slide 14 text

Copyright © 2023, Oracle and/or its affiliates 14 mle-js-fetch

Slide 15

Slide 15 text

Copyright © 2023, Oracle and/or its affiliates 15 MLE-FETCH Docs

Slide 16

Slide 16 text

Copyright © 2023, Oracle and/or its affiliates 16 Doing the same via PL/SQL in 11gR2 – 19c

Slide 17

Slide 17 text

Copyright © 2023, Oracle and/or its affiliates 17 Default Libraries Insufficient? Time to code or IMPORT!

Slide 18

Slide 18 text

Copyright © 2023, Oracle and/or its affiliates 18 Upload/importing multiple libraries is easy

Slide 19

Slide 19 text

Copyright © 2023, Oracle and/or its affiliates 19 Managing Environments Define dependencies for runtime (including debugging)

Slide 20

Slide 20 text

Copyright © 2023, Oracle and/or its affiliates 20 Set/Define your environment My new module utilizes routines from our MATHS environment

Slide 21

Slide 21 text

Copyright © 2023, Oracle and/or its affiliates 21 Example: Using JS to generate random, but useful, strings MIT License

Slide 22

Slide 22 text

Copyright © 2023, Oracle and/or its affiliates 22 We can import CHANCE as a Module and then Create one or more Call Specs, MAX FLEXIBILITY OR WE can simply create an INLINE Call Specification where the JS is defined alongside a single PL/SQL Spec, SIMPLICITY CHANCE.js has DOZENS of functions. For flexibility we may want to implement multiple different PL/SQL wrappers, so use Module + Call Spec Modules with Call Specs or In-Line Modules

Slide 23

Slide 23 text

Copyright © 2023, Oracle and/or its affiliates 23

Slide 24

Slide 24 text

Copyright © 2023, Oracle and/or its affiliates 24

Slide 25

Slide 25 text

Copyright © 2023, Oracle and/or its affiliates 25 Chance Examples: Generating URLs, Twitter Handles, Credit Card #s, Dates & More

Slide 26

Slide 26 text

Copyright © 2023, Oracle and/or its affiliates 26 • Dependencies Diagramming • Code Completion / Documentation Insight • MarkDown Documentation Generation • Code from Local File, Straight to Database or Both SQL Developer Web’s JavaScript Editor Features

Slide 27

Slide 27 text

Copyright © 2023, Oracle and/or its affiliates 27 Dependency Diagrams make many imports easy to visualize

Slide 28

Slide 28 text

Copyright © 2023, Oracle and/or its affiliates 28 JavaScript Completion & Insight

Slide 29

Slide 29 text

Copyright © 2023, Oracle and/or its affiliates 29 Save work locally (files/browser and/or to the Database)

Slide 30

Slide 30 text

Copyright © 2023, Oracle and/or its affiliates 30 Using a function exported from another module?

Slide 31

Slide 31 text

Copyright © 2023, Oracle and/or its affiliates 31 Markdown Java{Script}Doc: A Right-Click Away!

Slide 32

Slide 32 text

Copyright © 2023, Oracle and/or its affiliates 32 Post Execution Debugging: attach debug profile & Run!

Slide 33

Slide 33 text

Copyright © 2023, Oracle and/or its affiliates 33 Debugging: Seeing What’s What

Slide 34

Slide 34 text

Copyright © 2023, Oracle and/or its affiliates 34 Debugging: SQL Developer Web Makes this EASY

Slide 35

Slide 35 text

Copyright © 2023, Oracle and/or its affiliates 35 1. I have REST API for a resource in a DIFFERENT Oracle Database 2. I have a JavaScript routine to FETCH that HTTPS resource 3. I want to call this from a simple SQL SELECT ONE LAST EXAMPLE

Slide 36

Slide 36 text

Copyright © 2023, Oracle and/or its affiliates 36 Let’s GET a Beer!