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

Feat: Add Kyselify for View #3

Open
smhmayboudi opened this issue Sep 4, 2024 · 1 comment
Open

Feat: Add Kyselify for View #3

smhmayboudi opened this issue Sep 4, 2024 · 1 comment

Comments

@smhmayboudi
Copy link

You can add

import type { ColumnBaseConfig, ColumnDataType } from "drizzle-orm";
import { MySqlColumn } from "drizzle-orm/mysql-core";

export type KyselifyView<
  T extends {
    _: {
      selectedFields: Record<
        string,
        MySqlColumn<ColumnBaseConfig<ColumnDataType, string>, object>
      >;
    };
  },
> = {
  [K in keyof T["_"]["selectedFields"]]: T["_"]["selectedFields"][K] extends MySqlColumn<
    infer U,
    object
  >
    ? U extends { data: infer D }
      ? D
      : never
    : never;
};

Usage:

export const pocView = mysqlView("poc_view", {
  id: int("id").default(0).notNull(),
}).existing();
// .as(sql`SELECT id FROM poc_view`);

export interface Database {
  acknowledge: KyselifyView<typeof pocView>;
}
@smhmayboudi
Copy link
Author

import type { Column } from "drizzle-orm";

export type KyselifyView<
  T extends {
    _: {
      selectedFields: Record<string, Column>;
    };
  },
> = {
  [K in keyof T["_"]["selectedFields"] &
    string]: T["_"]["selectedFields"][K] extends Column<infer U, object>
    ? U extends { data: infer D }
      ? D
      : never
    : never;
};

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

1 participant