Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatic usage / Use without squid? #43

Open
JamesRamm opened this issue Jan 25, 2022 · 2 comments
Open

Programmatic usage / Use without squid? #43

JamesRamm opened this issue Jan 25, 2022 · 2 comments

Comments

@JamesRamm
Copy link

Hi,
Looks like a great tool 👍
Is it possible to use programmatically and without squid?

We have a large codebase which uses knex. Changing to use squid is a significant amount of work. However we would love to use this tool to check all possible SQL variations we generate and preferably do it programmatically within our unit tests.
Since knex can generate the plain SQL strings, is there a way to simply pass a SQL string for validation?

@albohlabs
Copy link

@JamesRamm Do you found a solution for your use case?

@shellscape
Copy link

This is basically all you need to duplicate:

postguard/src/cli.ts

Lines 66 to 77 in e9f6ed3

const { queries, tableSchemas } = parseSourceFile(loadSourceFile(filePath))
// TODO: Check that no table is defined twice
allQueries = [...allQueries, ...queries]
allTableSchemas = [...allTableSchemas, ...tableSchemas]
}
checkSchemasForDuplicates(allTableSchemas)
for (const query of allQueries) {
validateQuery(query, allTableSchemas)
}

As there's no "main" property in package.json, you'll need to specify the path. So

import { loadSourceFile, parseSourceFile } from "./parser"

will become

import { loadSourceFile, parseSourceFile } from "postguard/dist/parser"

You can view the package contents here: https://unpkg.com/browse/postguard@0.2.0/

The package doesn't ship any types either, so you'll have to redefine them in your app: https://github.com/andywer/postguard/blob/e9f6ed36a76c9a706f18b997a9044426831706e5/src/types.ts

I pinged the owner on twitter about updating things to avoid those steps, we'll see if they respond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants