postguard icon indicating copy to clipboard operation
postguard copied to clipboard

Programmatic usage / Use without squid?

Open JamesRamm opened this issue 3 years ago • 2 comments

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?

JamesRamm avatar Jan 25 '22 08:01 JamesRamm

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

albohlabs avatar Jul 12 '22 19:07 albohlabs

This is basically all you need to duplicate: https://github.com/andywer/postguard/blob/e9f6ed36a76c9a706f18b997a9044426831706e5/src/cli.ts#L66-L77

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/[email protected]/

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.

shellscape avatar Jun 05 '23 13:06 shellscape