Skip to content

[v3] .describe() doesn't work as expected #275

Closed

Description

@mohe2015
import { sql } from "./database.js";

const query = sql`SELECT * FROM users WHERE id = ${1}`

console.log(await query.describe())
console.log(await query.execute())

await sql.end()

Hi,

I expected this to show the describe and then the results but it shows the describe twice. Is this intended behaviour and is there a way to do what I want?

Activity

  1. changed the title [-][v3] sql`...`.describe() doesn't work as expected[/-] [+][v3] .describe() doesn't work as expected[/+] on Mar 13, 2022
  2. mohe2015 commented on Mar 13, 2022

    @mohe2015
    Author

    In particular I would love this to be as efficient as possible as I want to use this to add dynamic typescript to it. I don't know how the describe works internally or if that information is there anyways so it would have no overhead.

  3. mohe2015 commented on Mar 13, 2022

    @mohe2015
    Author

    Independent from this issue my idea is the following and I may create a PR once it's ready:

    import { sql } from "./database.js";
    
    const description = {
      types: [ 23 ],
      columns: {
        id: 23,
        username: 1043,
        openid_id: 1043,
        password_hash: 1043,
        type: 17425,
        project_leader_id: 23,
        group: 1043,
        age: 23,
        away: 16,
        password_changed: 16,
        force_in_project_id: 23,
        computed_in_project_id: 23,
        deleted: 16,
        last_updated_by: 23
      }
    } as const;
    
    type DescriptionTypes<T> = {
        [Property in keyof T]: T[Property] extends 23 ? number : unknown;
    };
    
    const args: DescriptionTypes<typeof description["types"]> = [1];
    
    let test: DescriptionTypes<typeof description["columns"]>;
    
    const { types: computed_query_types, columns: computed_column_types_1 } = await sql`SELECT * FROM users WHERE id = ${1}`.describe()
    
    const computed_column_types = Object.fromEntries(computed_column_types_1.map(v => [v.name, v.type]))
    
    const computed_description = {
      types: computed_query_types,
      columns: computed_column_types
    }
    
    console.log(computed_description);
    console.log(await sql<typeof description>`SELECT * FROM users WHERE id = ${1}`.execute());
    
    await sql.end();
  4. Repository owner locked and limited conversation to collaborators on Mar 13, 2022
  5. converted this issue into a discussion #276 on Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions