0.0.9 • Published 4 years ago

@goscript/goscript-app-api v0.0.9

Weekly downloads
9
License
ISC
Repository
-
Last release
4 years ago

GoScript Custom UI API

This npm package is used to communicate with GoScript to render and manipulate data through a customer user interface.

npm install --save @goscript/goscript-app-api

Initial Setup

Once you configure the goscript object with your api key and service id you can import it in any file and the settings will be saved.

import goscript from '@goscript/goscript-app-api';

await goscript.init();

Service Functions

// start the service
await goscript.service.start();

// stop the service
await goscript.service.stop();

// Trigger an event in the service (the passed object is optional)
await goscript.service.callEvent('event-name', { custom: 'data'});

// Call the RPC and receive the response
const rpcResponse = await goscript.service.callRpc('rpc-name', { custom: 'data' });

// Updates the service configuration
await goscript.service.updateConfig({ newConfig: 'data' });

// Fetch service startup injected config
await goscript.service.config();

Database Functions

Standard DB Functions

// Fetch all rows from a table
const results = await goscript.database.all(`SELECT * FROM servicename.mytable`);

// Run a query without expecting a result
await goscript.database.run(`INSERT INTO servicename.mytable (id, data) VALUES ('this-is-the-id', '{"name":"Matt"}')`);

ORM DB Functions

// Fetch the schema
const schema = await goscript.database.schema();

// List of database tables
const tables = Object.keys(schema),

For more details on ORM DB Functions see GoScript ORM Documentation

Fetching custom queries/datasources

// Fetch custom saved queries
const customQueries = await goscript.database.queries();

// Using a custom query
const query = customQueries['myqueryname'];
const results = await goscript.database.all(query.sql, [ 'param1', 'param2' ]);

const query2 = customQueries['myqueryname2'];
const results2 = await goscript.database.all(query.sql, { type: "event" });