Skip to content

Commit

Permalink
adding nullable for column property
Browse files Browse the repository at this point in the history
fixing where in delete to support model
fixing Insert with non string property
  • Loading branch information
pteyssedre committed Nov 20, 2018
1 parent eba0954 commit 143bad9
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mysqlconnector",
"version": "1.0.15",
"version": "1.0.16",
"description": "MySQL connector",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/queries/column/column-type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Column } from "./column";
export interface ColumnOptions {
isIdentity(): ColumnOptions | Column;
notNull(): ColumnOptions;
nullable(): ColumnOptions;
hasDefault(def: any): ColumnOptions;
}
export interface ColumnTypes {
Expand Down
2 changes: 2 additions & 0 deletions src/queries/column/column-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface ColumnOptions {

notNull(): ColumnOptions;

nullable(): ColumnOptions;

hasDefault(def: any): ColumnOptions;
}

Expand Down
1 change: 1 addition & 0 deletions src/queries/column/column.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export declare class Column extends Query implements ColumnOptions, ColumnTypes
asString(length?: number): this;
isIdentity(): this;
notNull(): this;
nullable(): this;
asFloat(): this;
asDecimal(n?: number, n2?: number): this;
asDouble(n?: number, n2?: number): this;
Expand Down
4 changes: 4 additions & 0 deletions src/queries/column/column.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/queries/column/column.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/queries/column/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export class Column extends Query implements ColumnOptions, ColumnTypes {
return this;
}

public nullable(): this {
this.sql += ` NULL`;
return this;
}

public asFloat(): this {
this.sql += ` ${ColumnDataType.FLOAT}`;
return this;
Expand Down
1 change: 0 additions & 1 deletion src/queries/delete.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import { Query } from "./query";
export declare class Delete extends Query {
static From(table: string): Delete;
private constructor();
where(clause: string): this;
}
7 changes: 0 additions & 7 deletions src/queries/delete.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/queries/delete.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions src/queries/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,4 @@ export class Delete extends Query {
super();
this.sql = "DELETE";
}

public where(clause: string): this {
if (!clause) {
throw new Error("no valid clause was provided");
}
this.sql += ` WHERE ${clause.trim()}`;
return this;
}
}
4 changes: 3 additions & 1 deletion src/queries/insert.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/queries/insert.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/queries/insert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Query} from "./query";
import { Query } from "./query";

export class Insert extends Query {

Expand Down Expand Up @@ -49,7 +49,9 @@ export class Insert extends Query {
}
this.sql += ") VALUES (";
for (let i = 0; i < keys.length; i++) {
this.sql += `${i === 0 ? "" : " "}'${obj[keys[i]].toString()}'${i + 1 < keys.length ? "," : ""}`;
const str = typeof obj[keys[i]] === "string" ?
`'${obj[keys[i]].toString()}'` : `${obj[keys[i]].toString()}`;
this.sql += `${i === 0 ? "" : " "}${str}${i + 1 < keys.length ? "," : ""}`;
}
this.sql += ")";
return this;
Expand Down
2 changes: 2 additions & 0 deletions test/src/dbcontext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("DbContext", () => {
.withColumnName("username").asString()
.withColumnName("FirstName").asString()
.withColumnName("LastName").asString()
.withColumnName("LoginCount").asInt32().nullable()
.withColumnName("Email").asString());
});
});
Expand All @@ -42,6 +43,7 @@ describe("DbContext", () => {
Email: "pierre@teyssedre.ca",
FirstName: "toto",
LastName: "toto",
LoginCount: 0,
username: "toto",
}));
should.exist(execute);
Expand Down

0 comments on commit 143bad9

Please sign in to comment.