Git Product home page Git Product logo

postguard's People

Contributors

andywer avatar darky avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

postguard's Issues

Add strict mode

Fail if type cannot be inferred in TypeScript code. So every (?) warning should become an error in strict mode.

Programmatic usage / Use without squid?

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?

Validating TypeScript types vs. database types

I'm not sure if this is something that postguard handles.

I have a table like this:

CREATE TABLE users (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid (),
  name text NOT NULL,
);

Then in my code:

const usersTable = defineTable('users', {
  id: Schema.Number,
  name: Schema.String,
});

type UserRecord = TableRow<typeof usersTable>;

console.log(await pool.query<UserRecord>(
  sql`SELECT id, name FROM users WHERE name = 'test'`,
));

Postguard sees no issues here. I was hoping it would fail since I defined id in the table as Schema.Number but the data type of the id column is uuid which is parsed as a string by node-postgres. Am I doing something wrong or this is not supported / not how it works?

Support for column aliases (`as`)

Thanks for writing this library, it's exactly what I was looking for.

Is there a way to support column aliases? Here's what I get right now:

โœ– Query validation failed in server/models/SomeModel.ts:39:13:

  No table in the query's scope has a column "user_token".
  Tables in scope: "some_table"

  37 | export async function getUserToken(requestId: string): Promise<string | null> {
  38 |   const { rows } = await database.query<{user_token: string}>(sql`
> 39 |     SELECT details -> 'user_token' AS user_token FROM some_table WHERE
     |            ^
  40 |       request_id = ${requestId} AND
  41 |       details -> 'user_token' IS NOT NULL
  42 |     ORDER BY timestamp DESC;

The workaround that seems to be fine is by using sql.raw:

    SELECT ${sql.raw('details -> \'user_token\' AS user_token')} FROM some_table WHERE 
      request_id = ${requestId} AND 
      details -> 'user_token' IS NOT NULL
    ORDER BY timestamp DESC;

Is this the best way to handle it? Thanks!

Query Parsing using spreadinsert

I am probably doing something wrong

this is the table in code

const usersTable = defineTable("users", {
  uuid: Schema.default(Schema.Uuid),
  phone: Schema.String,
  created_ts: Schema.default(Schema.Date),
});

export async function queryCreateUser(
  record: NewUserRecord
): Promise<UserRecord> {
  const query = sql`
  INSERT INTO users ${spreadInsert(record)} RETURNING phone
`;

my postgres table does not have the phone column at this point in time. Should postguard catch this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.