UNPKG

@tealbase/postgres-js

Version:
48 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostgrestClient = void 0; const builder_1 = require("./builder"); class PostgrestClient { /** * Creates a PostgREST client. * * @param url URL of the PostgREST endpoint. * @param headers Custom headers. * @param schema Postgres schema to switch to. */ constructor(url, { headers = {}, schema } = {}) { this.url = url; this.headers = headers; this.schema = schema; } /** * Authenticates the request with JWT. * * @param token The JWT token to use. */ auth(token) { this.headers['Authorization'] = `Bearer ${token}`; return this; } /** * Perform a table operation. * * @param table The table name to operate on. */ from(table) { const url = `${this.url}/${table}`; return new builder_1.PostgrestQueryBuilder(url, { headers: this.headers, schema: this.schema }); } /** * Perform a stored procedure call. * * @param fn The function name to call. * @param params The parameters to pass to the function call. */ rpc(fn, params) { const url = `${this.url}/rpc/${fn}`; return new builder_1.PostgrestQueryBuilder(url, { headers: this.headers, schema: this.schema }).rpc(params); } } exports.PostgrestClient = PostgrestClient; //# sourceMappingURL=index.js.map