Skip to content

Commit

Permalink
Export IMetadata and IMetadataOperationType
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubknejzlik committed Feb 10, 2024
1 parent 3d9c892 commit 87d8615
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/CreateTableAsSelect.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CreateTableAsSelect } from "./CreateTableAsSelect";
import { Cond } from "./Condition";
import { Q } from "./Query";
import { MySQLFlavor } from "./flavors/mysql";
import { MetadataOperationType } from "./interfaces";
import { IMetadataOperationType } from "./interfaces";

describe("CreateTableAsSelect", () => {
const initialSelectQuery = Q.select()
Expand Down Expand Up @@ -43,7 +42,7 @@ describe("CreateTableAsSelect", () => {
it("should return correct operation type", () => {
const ctas = Q.createTableAs(tableName, initialSelectQuery);
expect(ctas.getOperationType()).toEqual(
MetadataOperationType.CREATE_TABLE_AS
IMetadataOperationType.CREATE_TABLE_AS
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/CreateTableAsSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IMetadata,
ISequelizable,
ISerializable,
MetadataOperationType,
IMetadataOperationType,
OperationType,
} from "./interfaces";

Expand All @@ -18,8 +18,8 @@ export class CreateTableAsSelect
return new (this.constructor as any)(this._tableName, this._select.clone());
}

getOperationType(): MetadataOperationType {
return MetadataOperationType.CREATE_TABLE_AS;
getOperationType(): IMetadataOperationType {
return IMetadataOperationType.CREATE_TABLE_AS;
}

getTableNames(): string[] {
Expand Down
5 changes: 2 additions & 3 deletions src/CreateViewAsSelect.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { CreateViewAsSelect } from "./CreateViewAsSelect"; // Adjust the import path as needed
import { Cond } from "./Condition";
import { Q } from "./Query";
import { MySQLFlavor } from "./flavors/mysql";
import { MetadataOperationType } from "./interfaces";
import { IMetadataOperationType } from "./interfaces";

describe("CreateViewAsSelect", () => {
const initialSelectQuery = Q.select()
Expand Down Expand Up @@ -51,7 +50,7 @@ describe("CreateViewAsSelect", () => {
it("should return correct operation type", () => {
const cvas = Q.createViewAs(viewName, initialSelectQuery);
expect(cvas.getOperationType()).toEqual(
MetadataOperationType.CREATE_VIEW_AS
IMetadataOperationType.CREATE_VIEW_AS
);
});

Expand Down
6 changes: 3 additions & 3 deletions src/CreateViewAsSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IMetadata,
ISequelizable,
ISerializable,
MetadataOperationType,
IMetadataOperationType,
OperationType,
} from "./interfaces";

Expand All @@ -26,8 +26,8 @@ export class CreateViewAsSelect
);
}

getOperationType(): MetadataOperationType {
return MetadataOperationType.CREATE_VIEW_AS;
getOperationType(): IMetadataOperationType {
return IMetadataOperationType.CREATE_VIEW_AS;
}

getTableNames(): string[] {
Expand Down
8 changes: 4 additions & 4 deletions src/Mutation-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Q } from "./Query";
import { MetadataOperationType } from "./interfaces";
import { IMetadataOperationType } from "./interfaces";

describe("Query builder metadata", () => {
it("should return list of tables in insert query", () => {
Expand All @@ -19,13 +19,13 @@ describe("Query builder metadata", () => {
});
it("should get operation type", () => {
expect(Q.insert("table").getOperationType()).toEqual(
MetadataOperationType.INSERT
IMetadataOperationType.INSERT
);
expect(Q.update("table").getOperationType()).toEqual(
MetadataOperationType.UPDATE
IMetadataOperationType.UPDATE
);
expect(Q.delete("table").getOperationType()).toEqual(
MetadataOperationType.DELETE
IMetadataOperationType.DELETE
);
});
});
14 changes: 7 additions & 7 deletions src/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IMetadata,
ISequelizable,
ISerializable,
MetadataOperationType,
IMetadataOperationType,
OperationType,
} from "./interfaces";

Expand Down Expand Up @@ -48,8 +48,8 @@ export class DeleteMutation
{
protected _where: Condition[] = [];

public getOperationType(): MetadataOperationType {
return MetadataOperationType.DELETE;
public getOperationType(): IMetadataOperationType {
return IMetadataOperationType.DELETE;
}

public clone(): this {
Expand Down Expand Up @@ -101,8 +101,8 @@ export class InsertMutation
{
protected _values: Record<string, ConditionValue> = {};

public getOperationType(): MetadataOperationType {
return MetadataOperationType.INSERT;
public getOperationType(): IMetadataOperationType {
return IMetadataOperationType.INSERT;
}

public clone(): this {
Expand Down Expand Up @@ -155,8 +155,8 @@ export class UpdateMutation
protected _values: Record<string, ConditionValue> = {};
protected _where: Condition[] = [];

public getOperationType(): MetadataOperationType {
return MetadataOperationType.UPDATE;
public getOperationType(): IMetadataOperationType {
return IMetadataOperationType.UPDATE;
}

public clone(): this {
Expand Down
4 changes: 2 additions & 2 deletions src/Query-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Q } from "./Query";
import { Fn } from "./Function";
import { MetadataOperationType } from "./interfaces";
import { IMetadataOperationType } from "./interfaces";

describe("Query builder metadata", () => {
it("should return list of tables in simple query", () => {
Expand Down Expand Up @@ -60,6 +60,6 @@ describe("Query builder metadata", () => {
it("should get operation type for query", () => {
const query = Q.select();
const operation = query.getOperationType();
expect(operation).toEqual(MetadataOperationType.SELECT);
expect(operation).toEqual(IMetadataOperationType.SELECT);
});
});
6 changes: 3 additions & 3 deletions src/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
IMetadata,
ISequelizable,
ISerializable,
MetadataOperationType,
IMetadataOperationType,
OperationType,
} from "./interfaces";
import { DeleteMutation, InsertMutation, UpdateMutation } from "./Mutation";
Expand Down Expand Up @@ -77,8 +77,8 @@ export class QueryBase implements ISequelizable, IMetadata {
protected _tables: Table[] = [];
protected _joins: Join[] = [];

public getOperationType(): MetadataOperationType {
return MetadataOperationType.SELECT;
public getOperationType(): IMetadataOperationType {
return IMetadataOperationType.SELECT;
}

// @ts-ignore
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export { MySQLFlavor } from "./flavors/mysql";
export { Cond, Condition, type ConditionValue } from "./Condition";
export { Fn, Function } from "./Function";
export { Q, Query, SelectQuery } from "./Query";
export { type ISequelizable, type ISerializable } from "./interfaces";
export {
type ISequelizable,
type ISerializable,
type IMetadata,
type IMetadataOperationType,
} from "./interfaces";

export { type ISQLFlavor } from "./Flavor";
4 changes: 2 additions & 2 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ISerializable {
serialize(): string;
}

export enum MetadataOperationType {
export enum IMetadataOperationType {
SELECT = "select",
INSERT = "insert",
UPDATE = "update",
Expand All @@ -26,5 +26,5 @@ export enum OperationType {

export interface IMetadata {
getTableNames(): string[];
getOperationType(): MetadataOperationType;
getOperationType(): IMetadataOperationType;
}

0 comments on commit 87d8615

Please sign in to comment.