Coder Social home page Coder Social logo

v64500 / lealone-javascript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lealone-plugins/lealone-javascript

0.0 0.0 0.0 24 KB

在 Lealone 中使用 JavaScript 语言开发微服务应用或编写用户自定义函数

JavaScript 47.52% Java 47.45% Batchfile 5.03%

lealone-javascript's Introduction

lealone-javascript

在 Lealone 中使用 JavaScript 语言开发微服务应用或编写用户自定义函数

编译需要

  • jdk 1.8+
  • maven 3.8+

打包插件

运行 mvn clean package -Dmaven.test.skip=true

生成 jar 包 target\lealone-javascript-plugin-6.0.0.jar

假设 jar 包的绝对路径是 E:\lealone\lealone-plugins\javascript\target\lealone-javascript-plugin-6.0.0.jar

创建插件

先参考 lealone 快速入门 启动 lealone 数据库并打开一个命令行客户端

然后执行以下命令创建插件:

create plugin js
  implement by 'com.lealone.plugins.js.JavaScriptServiceExecutorFactory' 
  class path 'E:\lealone\lealone-plugins\javascript\target\lealone-javascript-plugin-6.0.0.jar';

要 drop 插件可以执行以下命令:

drop plugin js;

执行 drop plugin 会把插件占用的内存资源都释放掉

使用 JavaScript 开发微服务应用

E:\lealone\lealone-plugins\javascript\src\test\resources\js\hello_service.js

function hello(name) {
    return "hello " + name;
}

创建服务

执行以下 SQL 创建 js_hello_service

create service if not exists js_hello_service (
  hello(name varchar) varchar
)
language 'js' implement by 'E:\lealone\lealone-plugins\javascript\src\test\resources\js\hello_service.js';

也可以用以下简化版本,无需声明服务的方法,会自动调用 js 文件里定义的方法

create service if not exists js_hello_service
language 'js' implement by 'E:\lealone\lealone-plugins\javascript\src\test\resources\js\hello_service.js';

调用服务

执行以下 SQL 就可以直接调用 js_hello_service 了

sql> execute service js_hello_service hello('test');
+-------------------------+
| 'JS_HELLO_SERVICE.HELLO()' |
+-------------------------+
| hello test              |
+-------------------------+
(1 row, 2 ms)

sql>

lealone-javascript's People

Contributors

codefollower avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.