Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
drodrigues4 committed Jul 23, 2024
1 parent 2783479 commit 5bce7e5
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 213 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/release-to-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ jobs:
matrix:
package:
- drizzle-orm
- drizzle-zod
- drizzle-typebox
- drizzle-valibot
- eslint-plugin-drizzle
runs-on: ubuntu-20.04
services:
postgres-postgis:
Expand Down Expand Up @@ -163,35 +159,3 @@ jobs:
# Post release message to Discord
# curl -X POST -H "Content-Type: application/json" -d "{\"embeds\": [{\"title\": \"New \`${{ matrix.package }}\` release! 🎉\", \"url\": \"https://www.npmjs.com/package/${{ matrix.package }}\", \"color\": \"12907856\", \"fields\": [{\"name\": \"Tag\", \"value\": \"\`$tag\`\"}]}]}" ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
- name: Create GitHub release for ORM package
uses: actions/github-script@v6
if: matrix.package == 'drizzle-orm' && steps.checks.outputs.has_new_release == 'true'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const fs = require("fs");
const path = require("path");
const version = "${{ steps.checks.outputs.version }}";
const changelog = fs.readFileSync("${{ steps.checks.outputs.changelog_path }}", "utf8");
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `${version}`,
name: `${version}`,
body: changelog,
});
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: `${{ matrix.package }}-${version}-dist.tgz`,
data: fs.readFileSync(path.resolve("${{ matrix.package }}", "package.tgz")),
});
} catch (e) {
core.setFailed(e.message);
}
192 changes: 102 additions & 90 deletions drizzle-orm/src/singlestore-core/columns/guid.ts
Original file line number Diff line number Diff line change
@@ -1,111 +1,123 @@
import { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from "~/column-builder";
import { entityKind } from "~/entity";
import { SingleStoreColumn, SingleStoreColumnBuilder } from "./common";
import { AnySingleStoreTable } from "~/singlestore-core/table";
import { ColumnBaseConfig } from "~/column";
import { sql } from "~/sql/sql";
import { Equal } from "~/utils";

import { ColumnBaseConfig } from '~/column';
import { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder';
import { entityKind } from '~/entity';
import { AnySingleStoreTable } from '~/singlestore-core/table';
import { sql } from '~/sql/sql';
import { Equal } from '~/utils';
import { SingleStoreColumn, SingleStoreColumnBuilder } from './common';

export type SingleStoreGUIDBuilderInitial<TName extends string> = SingleStoreGUIDBuilder<{
name: TName;
dataType: "buffer";
columnType: "SingleStoreGUID";
data: Uint8Array;
driverParam: string;
enumValues: undefined;
generated: undefined;
}>

export class SingleStoreGUIDBuilder<T extends ColumnBuilderBaseConfig<"buffer", "SingleStoreGUID">> extends SingleStoreColumnBuilder<T, SingleStoreGUIDConfig> {
static readonly [entityKind]: string = "SingleStoreGUIDBuilder"

constructor(name: T["name"], config?: SingleStoreGUIDConfig) {
super(name, "buffer", "SingleStoreGUID")
}

/** @internal */
override build<TTableName extends string>(table: AnySingleStoreTable<{name: TTableName}>): SingleStoreGUID<MakeColumnConfig<T, TTableName>> {
return new SingleStoreGUID(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
}
name: TName;
dataType: 'buffer';
columnType: 'SingleStoreGUID';
data: Uint8Array;
driverParam: string;
enumValues: undefined;
generated: undefined;
}>;

export class SingleStoreGUIDBuilder<T extends ColumnBuilderBaseConfig<'buffer', 'SingleStoreGUID'>>
extends SingleStoreColumnBuilder<T, SingleStoreGUIDConfig>
{
static readonly [entityKind]: string = 'SingleStoreGUIDBuilder';

constructor(name: T['name'], config?: SingleStoreGUIDConfig) {
super(name, 'buffer', 'SingleStoreGUID');
}

/** @internal */
override build<TTableName extends string>(
table: AnySingleStoreTable<{ name: TTableName }>,
): SingleStoreGUID<MakeColumnConfig<T, TTableName>> {
return new SingleStoreGUID(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
}
}

export class SingleStoreGUID<T extends ColumnBaseConfig<"buffer", "SingleStoreGUID">> extends SingleStoreColumn<T> {
static readonly [entityKind]: string = "SingleStoreGUID"
export class SingleStoreGUID<T extends ColumnBaseConfig<'buffer', 'SingleStoreGUID'>> extends SingleStoreColumn<T> {
static readonly [entityKind]: string = 'SingleStoreGUID';

constructor(table: AnySingleStoreTable<{name: T["tableName"]}>, config: SingleStoreGUIDBuilder<T>["config"]) {
super(table, config)
}
constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreGUIDBuilder<T>['config']) {
super(table, config);
}

getSQLType(): string {
return "binary(16)"
}
getSQLType(): string {
return 'binary(16)';
}

override mapToDriverValue(value: string) {
return sql`UNHEX(REPLACE(${value}, "-", ""))`
}
override mapToDriverValue(value: string) {
return sql`UNHEX(REPLACE(${value}, "-", ""))`;
}
}

export type SingleStoreGUIDStringBuilderInitial<TName extends string> = SingleStoreGUIDStringBuilder<{
name: TName;
dataType: "string";
columnType: "SingleStoreGUIDString";
data: string;
driverParam: string;
enumValues: undefined;
generated: undefined;
}>

export class SingleStoreGUIDStringBuilder<T extends ColumnBuilderBaseConfig<"string", "SingleStoreGUIDString">> extends SingleStoreColumnBuilder<T, SingleStoreGUIDConfig> {
static readonly [entityKind]: string = "SingleStoreGUIDStringBuilder"

constructor(name: T["name"], config?: SingleStoreGUIDConfig) {
super(name, "string", "SingleStoreGUIDString")
}

/** @internal */
override build<TTableName extends string>(table: AnySingleStoreTable<{name: TTableName}>): SingleStoreGUIDString<MakeColumnConfig<T, TTableName>> {
return new SingleStoreGUIDString(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
}
name: TName;
dataType: 'string';
columnType: 'SingleStoreGUIDString';
data: string;
driverParam: string;
enumValues: undefined;
generated: undefined;
}>;

export class SingleStoreGUIDStringBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreGUIDString'>>
extends SingleStoreColumnBuilder<T, SingleStoreGUIDConfig>
{
static readonly [entityKind]: string = 'SingleStoreGUIDStringBuilder';

constructor(name: T['name'], config?: SingleStoreGUIDConfig) {
super(name, 'string', 'SingleStoreGUIDString');
}

/** @internal */
override build<TTableName extends string>(
table: AnySingleStoreTable<{ name: TTableName }>,
): SingleStoreGUIDString<MakeColumnConfig<T, TTableName>> {
return new SingleStoreGUIDString(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
}
}

export class SingleStoreGUIDString<T extends ColumnBaseConfig<"string", "SingleStoreGUIDString">> extends SingleStoreColumn<T> {
static readonly [entityKind]: string = "SingleStoreGUIDString"

constructor(table: AnySingleStoreTable<{name: T["tableName"]}>, config: SingleStoreGUIDStringBuilder<T>["config"]) {
super(table, config)
}

getSQLType(): string {
return "binary(16)"
}

override mapToDriverValue(value: string) {
return sql`UNHEX(REPLACE(${value}, "-", ""))`
}

override mapFromDriverValue(value: Uint8Array): string {
const hex = Buffer.from(value).toString("hex");
return `${hex.substring(0, 8)}-${hex.substring(8, 12)}-${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20)}`;
}
export class SingleStoreGUIDString<T extends ColumnBaseConfig<'string', 'SingleStoreGUIDString'>>
extends SingleStoreColumn<T>
{
static readonly [entityKind]: string = 'SingleStoreGUIDString';

constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreGUIDStringBuilder<T>['config']) {
super(table, config);
}

getSQLType(): string {
return 'binary(16)';
}

override mapToDriverValue(value: string) {
return sql`UNHEX(REPLACE(${value}, "-", ""))`;
}

override mapFromDriverValue(value: Uint8Array): string {
const hex = Buffer.from(value).toString('hex');
return `${hex.substring(0, 8)}-${hex.substring(8, 12)}-${hex.substring(12, 16)}-${hex.substring(16, 20)}-${
hex.substring(20)
}`;
}
}

export interface SingleStoreGUIDConfig<TMode extends "string" | "buffer" = "string" | "buffer"> {
mode?: TMode;
export interface SingleStoreGUIDConfig<TMode extends 'string' | 'buffer' = 'string' | 'buffer'> {
mode?: TMode;
}

/**
* Creates a column with the data type `BINARY(16)`
*
*
* Use config `{ mode: "string" }` for a string representation of the GUID
*/
export function guid<TName extends string, TMode extends SingleStoreGUIDConfig["mode"] & {}>(
name: TName,
config?: SingleStoreGUIDConfig<TMode>
): Equal<TMode, "string"> extends true ? SingleStoreGUIDStringBuilderInitial<TName> : SingleStoreGUIDBuilderInitial<TName>;
export function guid<TName extends string, TMode extends SingleStoreGUIDConfig['mode'] & {}>(
name: TName,
config?: SingleStoreGUIDConfig<TMode>,
): Equal<TMode, 'string'> extends true ? SingleStoreGUIDStringBuilderInitial<TName>
: SingleStoreGUIDBuilderInitial<TName>;
export function guid(name: string, config?: SingleStoreGUIDConfig) {
if (config?.mode === "string") {
return new SingleStoreGUIDStringBuilder(name, config)
}
return new SingleStoreGUIDBuilder(name, config)
}
if (config?.mode === 'string') {
return new SingleStoreGUIDStringBuilder(name, config);
}
return new SingleStoreGUIDBuilder(name, config);
}
75 changes: 39 additions & 36 deletions drizzle-orm/src/singlestore-core/columns/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
import { ColumnBaseConfig } from "~/column";
import { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from "~/column-builder";
import { entityKind } from "~/entity";
import { SingleStoreColumn, SingleStoreColumnBuilder } from "./common";
import { AnySingleStoreTable } from "~/singlestore-core/table";

import { ColumnBaseConfig } from '~/column';
import { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder';
import { entityKind } from '~/entity';
import { AnySingleStoreTable } from '~/singlestore-core/table';
import { SingleStoreColumn, SingleStoreColumnBuilder } from './common';

export type SingleStoreUUIDBuilderInitial<TName extends string> = SingleStoreUUIDBuilder<{
name: TName;
dataType: "string";
columnType: "SingleStoreUUID";
data: string;
driverParam: string;
enumValues: undefined;
generated: undefined;
}>

export class SingleStoreUUIDBuilder<T extends ColumnBuilderBaseConfig<"string", "SingleStoreUUID">> extends SingleStoreColumnBuilder<T> {
static readonly [entityKind]: string = "SingleStoreUUIDBuilder"

constructor(name: T["name"]) {
super(name, "string", "SingleStoreUUID")
}

/** @internal */
override build<TTableName extends string>(table: AnySingleStoreTable<{name: TTableName}>): SingleStoreUUID<MakeColumnConfig<T, TTableName>> {
return new SingleStoreUUID(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
}
name: TName;
dataType: 'string';
columnType: 'SingleStoreUUID';
data: string;
driverParam: string;
enumValues: undefined;
generated: undefined;
}>;

export class SingleStoreUUIDBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreUUID'>>
extends SingleStoreColumnBuilder<T>
{
static readonly [entityKind]: string = 'SingleStoreUUIDBuilder';

constructor(name: T['name']) {
super(name, 'string', 'SingleStoreUUID');
}

/** @internal */
override build<TTableName extends string>(
table: AnySingleStoreTable<{ name: TTableName }>,
): SingleStoreUUID<MakeColumnConfig<T, TTableName>> {
return new SingleStoreUUID(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
}
}

export class SingleStoreUUID<T extends ColumnBaseConfig<"string", "SingleStoreUUID">> extends SingleStoreColumn<T> {
static readonly [entityKind]: string = "SingleStoreUUID"
export class SingleStoreUUID<T extends ColumnBaseConfig<'string', 'SingleStoreUUID'>> extends SingleStoreColumn<T> {
static readonly [entityKind]: string = 'SingleStoreUUID';

constructor(table: AnySingleStoreTable<{name: T["tableName"]}>, config: SingleStoreUUIDBuilder<T>["config"]) {
super(table, config)
}
constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreUUIDBuilder<T>['config']) {
super(table, config);
}

getSQLType(): string {
return "varchar(36)"
}
getSQLType(): string {
return 'varchar(36)';
}
}

export function uuid<TName extends string>(name: TName): SingleStoreUUIDBuilderInitial<TName> {
return new SingleStoreUUIDBuilder(name)
}
return new SingleStoreUUIDBuilder(name);
}
Loading

0 comments on commit 5bce7e5

Please sign in to comment.