npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@omniindex/pgbc

v0.9.15

Published

The OmniIndex PostgresBC NodeJS driver

Downloads

5

Readme

OmniIndex/pgbc Node Package

OmniIndex Corporate logo on white background

  • 📒 OmniIndex Homomorphic Blockchain
  • 🏫 Postgres Machine Learning
  • 🏄‍♀️ Simple surface API
  • 🐦 Follow on LinkedIn
  • 🏷 ES6 Tagged Template Strings at the core

Pre-requisite

Introduction

OmniIndex PostgresBC is built directly in to the Postgres16 Database which enables much faster access to both base data and Machine Learning (ML) tools.

  • an image that can be deployed directly to a GCP project within a few minutes.
  • ready to use from within PGBC, PostgresML and PGVector.
  • ability to be placed on to an Nvidia GPU (Graphics card system) for extra power using NVIdia CUDA libraries.

Getting started

Installation

npm install -g @omniindex/pgbc

Note that we use ES6 throughout, you will need to update your package.json file to include "type":"module" key pairs

Usage

  1. Create your constructor by providing details from an environment variable file or other secure source. Never hard code these values

    * @param String SERVER (server address)
    * @param int PORT (server port)
    * @param String UID (system/managers username)
    * @param String DB database username (defaults to postgres)
    * @param String PWD (system/manager database password)

    Note: the use of SERVER, PORT, UID, DB, PWD are consistent with our JDBC, Python and other connectors

  2. Once you have these parameters you can start to build your script file:

    import pgbc from '@omniindex/pgbc';
  3. Next, use the constructor details to create an connected instance of pgbc

    A method called connect in the pgbc class. It establishes a connection to a PostgreSQL database using the pg library. It handles any errors that occur during the connection process and throws custom error messages.

    The method takes a single input parameter command, which is a string representing the SQL command to be executed.

    1. The method creates a new instance of the Client class from the pg library, passing in the necessary connection details.
    2. It then attempts to establish a connection to the PostgreSQL database using the connect method of the Client instance.
    3. If the connection is successful, the method executes the provided command using the query method of the Client instance.
    4. The results of the query are stored in the results variable.
    5. The method ends the connection to the database using the end method of the Client instance.
    6. The method returns the results object.
    7. If any errors occur during the connection or query execution, the method catches the error, extracts the relevant error message, and throws a custom Error object with the error message.

    Example:

    In this example, a new instance of the pgbc class is created with the necessary connection details. The connect method is then called with a SQL command as the input. The method returns the results of the query, which are logged to the console. If any errors occur, they are caught and logged to the console as well.

    const pgbcInstance = new pgbc('localhost', 5432, 'manager', 'user', 'password');
    const command = 'SELECT * FROM users';
    try {
        const results = await pgbcInstance.connect(command);
        console.log(results);
        } catch (error) {
    console.error(error);
    }

    Sample:

    //Set the login details along with the server address and port
    
    console.log('Creating connection class');
    function createConnection() {
        try {
            var postbc = new pgbc(SERVER, PORT, UID, DB, PWD);
        } catch (err) {
            console.error(err.message);
        }
    }
    
    createConnection();
    • replace all these with your values
    • replace the server port with your values if not the default for postgres
    • use the default database username 'postgres' if not set different

    If you don't have these values see Pre-requisites above you must have a running OmniIndex PostgresBC instance to use this package

  4. Units (Block organisation)

    OmniIndex PostgresBC is organised in by units. You can create as many units as you like, but you will need to create at least one to get started. Units are frequently used as functional organisational units, such as a 'Customer' or 'Supplier' or 'Employee' or 'Patient' etc. You can create as many units as you like, but you will need to create at least one to get started.

    Note that the unit name must be unique, if you try to create a unit with the same name as an existing unit, you will get an error.

    Units are referenced here by unit_name and are used in the creation of schemas and data objects.

Table of Contents

User Commands

We have listed the user commands separate from other commands for clarity

BlockChain Commands

Create BlockChain Schema (create_block_schema)

Create a New schema to hold data in your blockchain. All the considerations of good design are out of scope for this README, but you can find more by reading the documentation. The documentation includes a template you can use to map your existing datasets to an OmniIndex Homomorphic Blockchain.

Some elements of a schema are created for you automatically by the OmniIndex system and you don't need to worry about them. These are data objects that allow for the functioning of the blockchain and/or the homomorphic encryption of data objects.

  • oidxid - an incremental number for any object; if you create more than one object at a time, they will share a hash, but have their own, unique oidxid.
  • hash - unique to each minedata (write/post) event. Therefore, if you create an object such as a feelings video log, objects are created with the same hash, allowing them to have a relationship. This means you can link to the file, analyse the text in the file or just display it back to a user
  • priorhash - see above, this allows for acurate, immutable version history
  • file_meta (for speedy indexing)
  • file_searchable (makes searching on the file possible)
  • file_store (the file itself)
  • A feeling (the text extracted from the file, or it’s description etc.)
  • modified_date - A time stamp that allows for objects to be selected or worked with based on the moment they were created.
  • we also create a default index on the modified_date field to allow for fast searching on this field.

A method called create_block_schema within the pgbc class. It creates a new schema within a blockchain and allows for the creation of various data types using standard SQL. The method takes in parameters such as the user name, password, block name, and block DDL (Data Definition Language). It also has an optional parameter to output the command without running it. The method connects to the database using the connect method and executes the command to create the block schema. It returns the result as a JSON string.

Inputs:

  • user_name: The user name for authentication.
  • password: The password for authentication.
  • block_name: The name of the block schema to be created.
  • block_ddl: The Data Definition Language (DDL) for creating the block schema.
  • output (optional): A boolean value indicating whether to output the command without running it.

Usage example:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'user1';
const password = 'password1';
const block_name = 'block1';
const block_ddl = 'CREATE TABLE ...'; // The actual DDL for creating the block schema
const output = false;
const result = await pgbcInstance.create_block_schema(user_name, password,
 block_name, block_ddl, output);
console.log(result);
// Output: JSON string representing the result of creating the block schema```

Output:

  • If the output parameter is set to true, the method returns the constructed SQL command as a string.
  • Otherwise, it returns the result of creating the block schema as a JSON string.

Sample:

 new_schema = (await postbc.create_block_schema('user_name_email', 'password', 
 'unit_name', 'CREATE TABLE .entity_name(userencrypt VARCHAR(16), first_name 
 VARCHAR(16), last_name VARCHAR(16), zipcodeencrypt VARCHAR(12));'));

You can see from this example that valid PostgreSQL datatypes can be used in the creation of the schema.

NOTE: the use of the special keyword partial encrypt appended to any entity attribute that should be encrypted. This is a key concept of the OmniIndex Homomorphic Blockchain giving true web3 privacy and security at a user level.

Indexes

You can use the same format for creating indexes as you would in PostgreSQL, including specification of additional index types such as btree, brin, gin, gist etc. postgres indexes for more information

Sample:

 new_schema = (await postbc.create_block_schema('user_name_email', 'password', 
 'unit_name', 'CREATE INDEX ON .entity_name USING btree (modified_date);'));

Create UDT Type (create_udt_type)

a method called create_udt_type within the pgbc class. It creates a new User-Defined Type (UDT) for use within a blockchain. The method takes in parameters such as the user name, password, block name, and type DDL (Data Definition Language). It checks if all the required data is provided and then constructs a SQL command to create the UDT. If the output parameter is set to true, it returns the SQL command without executing it. Otherwise, it connects to the database using the connect method, executes the SQL command, and returns the result as a JSON string.

Inputs:

  • user_name (String): the user name for authentication
  • password (String): the password for authentication
  • block_name (String): the name of the blockchain
  • type_ddl (String): the Data Definition Language (DDL) for creating the UDT
  • output (Boolean, optional): whether to return the SQL command without executing it (default is false)

Usage example:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'john';
const password = 'password';
const block_name = 'block1';
const type_ddl = 'CREATE TYPE my_type AS (id INT, name TEXT)';
const output = false;

const result = await pgbcInstance.create_udt_type(user_name, password, block_name,
 type_ddl, output);
console.log(result);
// Output: '{"id": 1, "name": "my_type"}' (example JSON string)

In this example, we create a new instance of the pgbc class and provide the necessary parameters. We then call the create_udt_type method with the required inputs. The method connects to the database, executes the SQL command to create the UDT, and returns the result as a JSON string. Finally, we log the result to the console.

Create BlockChain Data (add_block_data)

Adding new data is one of the most frequent functions you will use. It is also one of the most powerful. You can add data to the blockchain in a number of ways, but the most common is to add a single object at a time. This is the most common use case for a user adding data to the blockchain.

Note the double escaped single quotes in the sample below. This is because the query is passed as a string and the single quotes are escaped to allow the query to be passed as a string. The query is then passed to the blockchain and the single quotes are escaped again to allow the query to be executed.

A method called add_block_data in the pgbc class. It adds a block to a given blockchain by executing a SQL command. It requires the user name, password, block name, and SQL command as inputs. It also has an optional parameter to output the command without running it. The method checks if all the required data is provided and then connects to the database using the connect method. It executes the SQL command and returns the result as a JSON string.

Inputs:

  • user_name (String): The user name for authentication.
  • password (String): The password for authentication.
  • block_name (String): The name of the block in the blockchain.
  • add_sql (String): The SQL command to add data to the block.
  • output (bool): Optional parameter to output the command without running it.
Plain Data Example

Usage Example:

onst pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'user1';
const password = 'password1';
const block_name = 'block1';
const add_sql = 'INSERT INTO table1 (column1) VALUES (value1)';
const output = false;

const result = await pgbcInstance.add_block_data(user_name, password, block_name,
 add_sql, output);
console.log(result);
// Output: JSON string representing the result of the SQL command
Encrypted Data Example with multiple data types

For a complete list of PostgreSQL datatypes see PostgreSQL datatypes

  1. First, a sample scheme with encrypted and multiple data types

    create_block_schema('user_name_email','password', 'unit_name', <br>
    'CREATE TABLE .entity_name(attribute** *TIMESTAMPTZ, BOOL, <br>
    VARCHAR(), INTEGER, etc (remember to append encrypt to any attribute/object <br>
    you want to encrypt* **);');**

    Example of a schema with encrypted and multiple data types

    new_schema = (await postbc.create_block_schema('user_name_email', 'password',
    'unit_name', 'CREATE TABLE .encryption_tests(log_time TIMESTAMPTZ, active
    BOOL, nickname VARCHAR(16), age INTEGER, cc_numencrypt VARCHAR(16),
    postcodeencrypt VARCHAR(12));'));
  2. Second, a sample insert with encrypted and multiple data types

    add_block_data('user_name_email','password', 'unit_name', <br>
    'INSERT INTO .entity_name(attribute object names) <br>
    VALUES (attribute values** *must be double escaped where strings* <br>
    **);')

    Example of an insert with encrypted and multiple data types

    insert_data = (await postbc.add_block_data('user_name_email', 'password',
    'unit_name', 'INSERT INTO .encryption_tests(log_time, active, nickname, age,
    cc_numencrypt, postcodeencrypt) VALUES (\'\'2023-04-12 12:05:06
    America/New_York\'\', FALSE, \'\'WiperZulu\'\', 29, \'\'4659017358706018\'\',
    \'\'PO20 2GZ\'\' );'));

Create a data type

This call executes a SQL command to create a block schema using the pgbc.create_block_schema function and returns the results.

You can create 'nested' or 'array' data types by using the following syntax:

A method called create_data_type in the pgbc class. It creates a new data type for use within a blockchain schema. The method takes in parameters such as the user name, password, block name, and type DDL (Data Definition Language). It checks if all the required data is provided and then constructs a SQL command to create the data type. If the output parameter is set to true, it returns the SQL command without executing it. Otherwise, it connects to the PostgreSQL database using the connect method, executes the SQL command, and returns the result as a JSON string.

Inputs:

  • user_name: The user name for connecting to the database.
  • password: The password for connecting to the database.
  • block_name: The name of the blockchain schema.
  • type_ddl: The Data Definition Language (DDL) statement for creating the data type.
  • output (optional): A boolean flag indicating whether to return the SQL command without executing it. Defaults to false.

Usage example:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'user1';
const password = 'password1';
const block_name = 'block1';
const type_ddl = 'CREATE TYPE my_type AS (id INT, name TEXT)';
const output = false;

const result = await pgbcInstance.create_data_type(user_name, password,
 block_name, type_ddl, output);
console.log(result);
// Output: JSON string representing the result of the SQL command execution

Outputs:

  • If the output parameter is set to true, the method returns the SQL command as a string.
  • If the SQL command execution is successful, the method returns the result of the execution as a JSON string.
  • If there is an error during the SQL command execution, the method returns false.

Sample:

my_dtype = (await postbc.create_data_type(new_user, password, 'docs', 
'CREATE TYPE .my_type AS (log_time VARCHAR(32), called_byencrypt VARCHAR(128),
message TEXT);'))

Encrypted searches

You can see in the examples following that we are asking for the object userencrypt and searching for the object zipcodeencrypt. userencrypt will automatically be returned in plain text, if you have passed the correct details and a key is available. Searching on encrypted objects requires that you surround that part of the query with {} curly braces. This tells pgbc to handle this data and object as a homomorphic type, and surrounding the cypher data between %%.

Inputs

  • user_name (String): The username of the user performing the search.
  • password (String): The password of the user performing the search.
  • is_manager (Boolean): Indicates whether the user is a manager or not.

is_manager = true means the user is a manager and can search all data in the encrypted blocks, but cannot see the data in plain text. If false, then user can search their data within this block but no-one elses

  • unit_name (String): The name of the blockchain to search within.
  • search_sql (String): The SQL query to execute for the search.

Example usage:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'user1';
const password = 'password1';
const is_manager = false;
const unit_name = 'block1';
const search_sql = 'SELECT * FROM table1';
const result = await pgbcInstance.search_block_data(user_name, password,
is_manager, block_name, search_sql);
console.log(result);

Using the sample below, we can see that we are searching for the object value in the encrypted object cc_numberencrypt. Without ever decrypting the data, we can search for the data we are looking for. This is a key concept of the OmniIndex Homomorphic Blockchain giving true web3 privacy and security at a user.

Sample:

await pgbcInstance.search_block_data('user_name_email', 'password', false, 'docs',
'SELECT nickname, cc_numencrypt FROM .encryption_tests WHERE
{ cc_numencrypt LIKE \'\'%58706%\'\'};')

Create New User (add_user)

Create a 'New User' within the database. This is distinct from a database user, this is a user entity which is used to produce a homomorphic data entity within the blockchain which is a key concept of the OmniIndex Homomorphic Blockchain giving true web3 privacy and security at a user level.

A method called add_user in the pgbc class. It adds a new user to the system by executing a SQL command using the connect method. It checks if all the required parameters are provided and constructs the SQL command accordingly. If the output parameter is set to true, it returns the SQL command without executing it. Otherwise, it executes the command and returns the result as a JSON string.

Inputs:

  • user_name (String): The username of the new user.
  • password (String): The password of the new user.
  • output (Boolean): Optional parameter to control whether to return the SQL command without executing it. Defaults to false.

Usage example:

const pgbcInstance = new pgbc('localhost', 5432, 'manager', 'postgres', 'password');
const result = await pgbcInstance.add_user('new_user', 'new_password');
console.log(result);
// Output: {"column1": "value1", "column2": "value2", ...}

Sample:

example_user = (await postbc.add_user('[email protected]', 'password@1234'));

Update User (modify_user)

Update an existing user within the database. Updates would typically be change of password. This is also the place to promote a user to have 'Manager' role meaning they are able to work with other user's encrypted blocks in the blockchain (note that they can never decrypt another users data, but they can the results of homomorphic search agregation and machine learning)

A method called modify_user in the pgbc class. It is used to modify a user by changing their password or elevating their permissions.

Inputs:

  • manager_user: The username of the manager who is making the modification.
  • manager_password: The password of the manager.
  • user_name: The username of the user to be modified.
  • password: The current password of the user.
  • new_password: The new password for the user (optional).
  • to_manager: A boolean value indicating whether the user's permissions should be elevated (optional). (true = promote to manager false = normal user default = false)
  • output: A boolean value indicating whether to return the command without running it (optional).

Users may update their own password, but must supply their old password too

Usage example:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const result = await pgbcInstance.modify_user(manager_user, manager_password,
 user_name, password, new_password, to_manager);
console.log(result);

Sample:

modified_user = (await postbc.modify_user('[email protected]',
'complex-password-21', '[email protected]', '12343456@12345', 
'1234345678@12345678', false))

Suspend User (suspend_user)

Suspend an existing user within the database. Suspend an inactive user/manager for example if someone leaves employment or responsibilities.

  • Can be reversed with enable_user

The method checks if all the required data is provided and then constructs a SQL command to suspend the user. It then connects to the database using the connect method and executes the command. The method returns the result of the command as a JSON string.

Inputs:

  • manager_user (String): The username of the manager.
  • manager_password (String): The password of the manager.
  • user_name (String): The username of the user to be suspended.
  • output (Boolean, optional): Whether to output the command without running it.

Usage Example:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const result = await pgbcInstance.suspend_user(manager_user, manager_password, user_name);
console.log(result);

Sample:

suspended_user = (await postbc.suspend_user('[email protected]',
'complex-password-21', '[email protected]'))

Enable User (enable_user)

Enable a suspended user within the database. Enable an inactive user/manager for example if someone comes back to employment or reinstates their responsibilities.

  • Can be reversed with suspend_user

A method called enable_user in the pgbc class. It is used to re-enable a user's access to the system or elevate their permissions.

Inputs:

  • manager_user (String): The username of the manager.
  • manager_password (String): The password of the manager.
  • user_name (String): The username of the user to enable.
  • output (Boolean): Optional parameter to specify whether to return the command without running it. Defaults to false.

Usage Example:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const result = await pgbcInstance.enable_user(manager_user, manager_password, user_name);
console.log(result);

In this example, a new instance of the pgbc class is created with the required parameters. Then, the enable_user method is called with the manager_user, manager_password, and user_name parameters. The result is logged to the console

Sample:

enabled_user = (await postbc.enable_user('[email protected]',
'complex-password-21', '[email protected]'))

Delete User (delete_user)

WARNING - Use with extreme caution, irreversible.

Delete a user within the database. Should only be used to achieve so called 'Right to be Forgotten' regulation etc as is irreversible, causing the destruction of the encryption key for this user. There is no way back. Consider the use of suspend_user in any use case other than to achieve a 'Right to be Forgotten'

  • Can never be reversed

The method first checks if the manager's credentials and the user's username are provided. If all the required data is provided, it constructs a SQL command to delete the user and executes it using the connect method. The method returns the result of the command as a JSON string.

Inputs:

  • manager_user: The username of the manager.
  • manager_password: The password of the manager.
  • user_name: The username of the user to be deleted.
  • output (optional): A boolean value indicating whether to return the command without running it. Defaults to false.

Example Usage:

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const result = await pgbcInstance.delete_user(manager_user, manager_password, user_name);
console.log(result);

In this example, we create an instance of the pgbc class and call the delete_user method with the manager_user, manager_password, and user_name parameters. The method will execute the SQL command to delete the user and return the result as a JSON string. The result is then logged to the console.

Sample:

delete_user = (await postbc.delete_user('[email protected]','complex-password-21'
, '[email protected]'))

AI and Machine Learning

OmniIndex Homomorphic Blockchain is built directly in to the Postgres16 Database which enables much faster access to both base data and Machine Learning (ML) tools. Read more on PostgresML postgres.ai

Hugging Face is a leading provider of ML models and tools. Read more on Hugging Face huggingface.co their tools are available in a number of languages including Python, Java, Javascript and more.

In addition to the standard PostgresML tools, OmniIndex Homomorphic Blockchain includes a number of additional tools to enable the use of ML on encrypted data including a bot which takes a query and returns the results of the query in plain text.

Commands / Prompts

Command that return a string or an object can be handled by adding commands or 'prompts' that allows OmniIndex to return bot queries in plain text.

Add a command

This method is called omni_add_command in the pgbc class. It adds a command to a given block unit by executing a SQL query, which adds a row to the NLP base which the bot can use for it's language processing.

Inputs

  • user_name (String): The username of the user executing the command.
  • password (String): The password of the user executing the command.
  • unit_name (String): The name of the blockchain to add the command to.
  • lexicon_phrases (String): The lexicon phrases associated with the command.
  • command_text (String): The text of the command.
  • description (String): The description of the command.

Example Usage

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const result = await pgbcInstance.omni_add_command(user_name, password, 
blockchain, lexicon_phrases, command_text, description);
console.log(result);

Sample:

add_command = await pgbcInstance.omni_add_command(
'user_name_email', 'password', false, 'docs', 'get time, what time, is it now,
i need the time','SELECT CURRENT_TIME(0);','Get the current time.' );
Use a command

a method called omni_command in the pgbc class. It takes in several parameters including user_name, password, blockchain, and phrases. It checks if all the required data is provided and then constructs a SQL command using the input parameters. It connects to the PostgreSQL database using the connect method and executes the SQL command. The results are then processed and returned as a JSON string.

Inputs

  • user_name (String): The username of the user.
  • password (String): The password of the user.
  • unit_name (String): The name of the blockchain.
  • phrases (String): The phrases to be used for the command.

Example Usage

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const result = await pgbcInstance.omni_command(user_name, password, unit_name, phrases);
console.log(result);

Sample:

new_command = await pgbcInstance.omni_command('user_name_email', 'password', 'docs',
'what time is it now');

Outputs

  • A JSON string containing the results of the command.

Remember that this is an Natural Language Processing (NLP) bot, so you can use any of the phrases you have added to the lexicon for the command, but the bot will return the results of the command you have specified or near match

Train ML

Train: This is the process of training a machine learning model on your data. In PostgresML, you can use the OmniIndex extension to directly use your blockchain to train with your data, you can perform training using SQL queries. For example, you can train a regression model on a table of historical sales data to forecast future sales. Read more here

A method called train in the pgbc class. The train method is used to train a blockchain model by executing a SQL command on the blockchain.

Example Usage

const pgbcObj = new pgbc(server, port, manager_user, user, password);
const user_name = 'user1';
const password = 'password1';
const unit_name = 'blockchain1';
const training_data = 'training data';
const result = await pgbcObj.train(user_name, password, unit_name, training_data);
console.log(result);

Sample:

await postbc.train('user1','password1','sale',
'project_name => \'\'My Classification Project\'\', task => 
\'\'classification\'\', relation_name => \'\' .sales_records\'\', 
y_column_name => \'\'message\'\'');

Input:

  • user_name: the username of the user
  • password: the password of the user
  • unit_name: the name of the blockchain
  • training_data: the training data for the blockchain model

Outputs:

  • The result of the SQL command execution, returned as a JSON string.

Transform ML

Transform: This refers to the process of transforming your data using a trained model. In PostgresML, you can use the OmniIndex extention with the pgml.transform function to perform various tasks such as translation, sentiment analysis, and more. For instance, you can translate text from English to French or perform sentiment analysis on a given text. Read more here and here

This method, transform, is a part of the pgbc class and is used to transform data in a blockchain. It takes in the user's name, password, the blockchain name, and the data to be transformed as inputs.

Example Usage

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'John';
const password = 'password123';
const unit_name = 'Schools';
const transform_data = 'data to be transformed';
const result = await pgbcInstance.transform(user_name, password, blockchain, transform_data);
console.log(result);

Output:

{"result": "transformed data"}

Inputs

  • user_name (string): The name of the user.
  • password (string): The password of the user.
  • unit_name (string): The name of the blockchain.
  • transform_data (string): The data to be transformed.

Outputs

Sample:

await postbc.transform('user1','password1','Schools',
'task => \'\'{"task" : "fill-mask"}\'\'::JSONB,inputs => 
ARRAY[\'\'Paris is the  of France.\'\']')

Embed ML

Embed: PostgresML enhances your existing PostgreSQL database to be used as a vector database by generating embeddings from text stored in your OmniIndex blockchain entities. To generate embeddings, you can use the pgml.embed function, which takes a transformer name and a text value as input. This function automatically downloads and caches the transformer for future reuse. These embeddings can be used to measure the similarity of text strings, which is essential for tasks like information retrieval, document clustering, and more.

Shows the implementation of the embed method in the pgbc class. The method is used to embed data into a specified blockchain.

In this example, we create an instance of the pgbc class and pass the required parameters. We then call the embed method with the user_name, password, blockchain, and embed_data as inputs. The method will embed the data into the specified blockchain and return the result.

Example Usage

const pgbcInstance = new pgbc(server, port, manager_user, user, password);
const user_name = 'user1';
const password = 'password1';
const unit_name = 'unit_name1';
const embed_data = 'data to be embedded';

const result = await pgbcInstance.embed(user_name, password, unit_name, embed_data);
console.log(result);

Inputs

  • user_name (string): The username of the user embedding the data.
  • password (string): The password of the user embedding the data.
  • unit_name (string): The name of the blockchain where the data will be embedded.
  • embed_data (string): The data to be embedded into the blockchain.

Outputs

  • The method returns a JSON string representation of the result of the SQL command execution. The result contains information about the success or failure of the embedding process.

Sample:

await postbc.embed('user1','password1','schools','project_name => 
\'\'My Classification Project\'\', task => \'\'classification\'\', 
relation_name => \'\' .school_district\'\', y_column_name => \'\'message\'\'');