@ptkl/sdk - v1.3.4
    Preparing search index...

    Base client for the platform API Classes that extend PlatformBaseClient have intentins of only working in platform context

    PlatformBaseClient

    The axios instance to use for the client

    // if sdk is used in the forge app that is running in the platform context
    const utils = new ComponentUtils()
    // this won't work outside of platform context because client needs authtorization to communicate with the API.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • Optionaloptions: { env?: string; host?: string; token?: string }

      Returns default

    Properties

    client: AxiosInstance
    env: null | string = null
    host: null | string = null
    token: null | string = null

    Methods

    • Create a new database connection

      Supports multiple database types:

      • MySQL: Use credentials with host, dbname, user, password
      • PostgreSQL: Use credentials with host, dbname, user, password
      • MongoDB: Use DSN connection string
      • BigQuery: Use service_account_json and project_id

      Parameters

      Returns Promise<AxiosResponse<RatchetConnection, any>>

      Created connection details

      const ratchet = new Ratchet();

      // MySQL/PostgreSQL connection
      await ratchet.createConnection({
      id: 'users_db',
      type: 'MySQL',
      credentials: {
      type: 'Credentials',
      host: 'localhost',
      dbname: 'users',
      user: 'admin',
      password: 'secret'
      }
      });

      // MongoDB connection
      await ratchet.createConnection({
      id: 'mongo_db',
      type: 'MongoDB',
      credentials: {
      type: 'DSN',
      dsn: 'mongodb://localhost:27017/mydb'
      }
      });

      // BigQuery connection
      await ratchet.createConnection({
      id: 'analytics_bq',
      type: 'BigQuery',
      credentials: {
      type: 'ServiceAccount',
      service_account_json: '{"type":"service_account",...}',
      project_id: 'my-project-id'
      }
      });
    • Delete a database connection

      Parameters

      • id: string

        Connection ID to delete

      Returns Promise<AxiosResponse<{ status: boolean }, any>>

      Success status

      const ratchet = new Ratchet();
      await ratchet.deleteConnection('users_db');
    • Get a specific database connection by ID

      Parameters

      • id: string

        Connection ID

      Returns Promise<AxiosResponse<RatchetConnection, any>>

      Connection details including queries

      const ratchet = new Ratchet();
      const connection = await ratchet.getConnection('users_db');
      console.log(connection.data.queries); // Available queries for this connection
    • Get all database connections for the current project

      Returns Promise<AxiosResponse<RatchetConnection[], any>>

      List of all configured ratchet connections

      const ratchet = new Ratchet();
      const connections = await ratchet.getConnections();
      console.log(connections.data); // Array of connections
    • Inspect and execute a custom query without saving it

      This allows you to test queries before saving them to a connection.

      Type Parameters

      • T = any

      Parameters

      Returns Promise<AxiosResponse<RatchetQueryResponse<T>, any>>

      Query execution results

      const ratchet = new Ratchet();
      const result = await ratchet.inspectQuery({
      name: 'users_db.test_query',
      query: {
      id: 'test_query',
      expression: 'SELECT * FROM users WHERE email = $1'
      },
      params: ['user@example.com']
      });
    • Execute a predefined database query

      Runs a query that has been previously configured in a ratchet connection. The query is identified by a qualified name in the format: connectionId.queryId

      Type Parameters

      • T = any

      Parameters

      • name: string

        Qualified name of the query (format: connectionId.queryId)

      • params: any[] | Record<string, any>

        Array of parameters to pass to the query

      Returns Promise<AxiosResponse<RatchetQueryResponse<T>, any>>

      Query execution results

      const ratchet = new Ratchet();

      // Execute a query with parameters
      const result = await ratchet.query('users_db.get_user_by_id', [123]);

      // Execute a query without parameters
      const allUsers = await ratchet.query('users_db.get_all_users', []);
    • Parameters

      • client: AxiosInstance

      Returns default

    • Test a database connection without saving it

      Parameters

      Returns Promise<AxiosResponse<{ status: boolean }, any>>

      Success status if connection is valid

      const ratchet = new Ratchet();
      const isValid = await ratchet.testConnection({
      id: 'test_db',
      type: 'postgres',
      credentials: {
      type: 'postgres',
      host: 'localhost',
      dbname: 'test',
      user: 'admin',
      password: 'secret'
      }
      });
    • Update an existing database connection

      Parameters

      Returns Promise<AxiosResponse<{ status: boolean }, any>>

      Success status

      const ratchet = new Ratchet();
      await ratchet.updateConnection({
      id: 'users_db',
      type: 'postgres',
      credentials: {
      type: 'postgres',
      host: 'localhost',
      dbname: 'users',
      user: 'admin',
      password: 'new_secret'
      },
      queries: [
      { id: 'get_user', expression: 'SELECT * FROM users WHERE id = $1' }
      ]
      });