Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/services/downloader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from "https://deno.land/std@0.133.0/path/mod.ts";
import { SupportedOs } from "../types/platforms.ts";
import { darwinUnpack, unzip } from "./unpacker.ts";
import { chomod } from "../utils.ts";
import { chomod } from "../utils/os.ts";

export class Downloader {
private os: string;
Expand Down Expand Up @@ -29,7 +29,7 @@ export class Downloader {

try {
await res.body?.pipeTo(file.writable).finally(
() => file.close() //TODO: fix bad resource id when closing file
() => file.close(), //TODO: fix bad resource id when closing file
);
} catch (error) {
console.error(`ERROR: [downloadFile] ${error.message}`);
Expand Down
12 changes: 8 additions & 4 deletions src/stackql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ Deno.test("StackQL runQuery - Successful Execution", async () => {
await removeStackQLDownload();
const stackQL = new StackQL();
await stackQL.initialize({ serverMode: false });
const pullQuery = "REGISTRY PULL okta;";
const testQuery = "SHOW PROVIDERS"; // Replace with a valid query for your context
const pullQuery = "REGISTRY PULL github;";
const providerQuery = "SHOW PROVIDERS";
const githubTestQuery =
`SELECT id, name from github.repos.repos where org='stackql'`;

// Act
await stackQL.runQuery(pullQuery);
const result = await stackQL.runQuery(testQuery);
const result = await stackQL.runQuery(providerQuery);
const githubResult = await stackQL.runQuery(githubTestQuery);

// Assert
assertStringIncludes(result, "name");
assertStringIncludes(result, "version");
assertStringIncludes(result, "okta");
assertStringIncludes(result, "github");
assertStringIncludes(githubResult, "stackql");
});

Deno.test("StackQL runServerQuery - Successful Execution", async () => {
Expand Down
32 changes: 17 additions & 15 deletions src/stackql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertExists } from "https://deno.land/std@0.206.0/assert/assert_exists.ts";
import { Downloader } from "./services/downloader.ts";
import { fileExists } from "./utils.ts";
import { fileExists } from "./utils/os.ts";
import { Server } from "./services/server.ts";
import { Client } from "https://deno.land/x/postgres@v0.17.0/client.ts";

Expand All @@ -12,10 +12,11 @@ export interface StackQLConfig {

export class StackQL {
private binaryPath?: string;
private downloader: Downloader = new Downloader();
private downloader: Downloader = new Downloader(); //TODO: Change to DI
private serverMode = false;
private connection?: Client; //TODO: wrap connection into Server class
private format: "object" = "object";
private params: string[] = [];
constructor() {
}
public async initialize(config: StackQLConfig) {
Expand All @@ -31,21 +32,11 @@ export class StackQL {
this.binaryPath = await this.downloader.setupStackQL();
}

private async setupConnection(connectionString?: string) {
const server = new Server();
this.connection = await server.connect(connectionString);
}

public async closeConnection() {
if (this.connection) {
await this.connection.end();
}
}

public async runQuery(query: string) {
assertExists(this.binaryPath);
const args = ["exec", query].concat(this.params);
const process = new Deno.Command(this.binaryPath, {
args: ["exec", query], // Ensure this command is correct
args,
stdout: "piped",
stderr: "piped",
});
Expand All @@ -62,13 +53,24 @@ export class StackQL {
throw new Error(`StackQL query failed: ${errorMessage}`);
}
}

//////////////////////Server mode related methods
private async queryObjectFormat(query: string) {
assertExists(this.connection);
const pgResult = await this.connection.queryObject(query);
return pgResult.rows;
}

private async setupConnection(connectionString?: string) {
const server = new Server();
this.connection = await server.connect(connectionString);
}

public async closeConnection() {
if (this.connection) {
await this.connection.end();
}
}

public async runServerQuery(query: string) {
try {
if (this.format === "object") {
Expand Down
File renamed without changes.