Skip to main content

Worker Javascript

The Worker-Java executes the provided Javascript code at the remote worker. More information about the worker at: https://github.com/apioo/fusio-worker-javascript

Example

module.exports = async function(request, context, connector, response, dispatcher, logger) {
const connection = await connector.getConnection('App');
const filter = request.arguments['filter'];

const values = [];
let query = 'SELECT id, title, content, insert_date FROM my_blog';
if (filter) {
query += ' WHERE title LIKE ?'
values.push('%' + filter + '%');
}

const entries = [];
const [result] = await connection.execute(query, values);
result.forEach((row) => {
entries.push({
id: row.id,
name: row.title,
description: row.content,
insertDate: row.insert_date,
});
});

return response.build(200, {}, {
entries: entries
});
};

Types

This table contains an overview which connection types are implemented and which implementation is used:

TypeImplementation
Fusio.Adapter.Sql.Connection.Sqlmysql2 / pg
Fusio.Adapter.Sql.Connection.SqlAdvancedmysql2 / pg
Fusio.Adapter.Http.Connection.Httpaxios
Fusio.Adapter.Mongodb.Connection.MongoDBmongoose
Fusio.Adapter.Elasticsearch.Connection.Elasticsearch@elastic/elasticsearch

Video