From edef2fc421126e56371a43490fedfaa280a474d0 Mon Sep 17 00:00:00 2001 From: David Graham Date: Fri, 29 Jul 2022 15:24:58 -0600 Subject: [PATCH] Rename mysqlAddress to host Configure the connection with a host name rather than full URL. --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1c4c15f..7b547f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { utf8Encode } from './text.js' export interface Credentials { username: string password: string - mysqlAddress: string + host: string } export interface QueryResultRow { @@ -92,13 +92,13 @@ export class Connection { } private async createSession(): Promise { - const url = `${this.credentials.mysqlAddress}/psdb.v1alpha1.Database/CreateSession` + const url = new URL('/psdb.v1alpha1.Database/CreateSession', `https://${this.credentials.host}`) const { session } = await this.postJSON(url) this.session = session return session } - private async postJSON(url: string, body = {}): Promise { + private async postJSON(url: string | URL, body = {}): Promise { const auth = btoa(`${this.credentials.username}:${this.credentials.password}`) const response = await fetch(url, { method: 'POST', @@ -120,7 +120,7 @@ export class Connection { async execute(query: string): Promise { const startTime = Date.now() - const url = `${this.credentials.mysqlAddress}/psdb.v1alpha1.Database/Execute` + const url = new URL('/psdb.v1alpha1.Database/Execute', `https://${this.credentials.host}`) const saved = await this.postJSON(url, { query: query, session: this.session