Skip to content

Commit

Permalink
refactor: refactor deprecated new Buffer to Buffer.from (typeorm#5924)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaznovac authored and Svetlozar committed Jan 12, 2021
1 parent f208779 commit f6bb324
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions src/driver/sqljs/SqljsDriver.ts
Expand Up @@ -75,7 +75,7 @@ export class SqljsDriver extends AbstractSqliteDriver {

return this.queryRunner;
}

/**
* Loads a database from a given file (Node.js), local storage key (browser) or array.
* This will delete the current database!
Expand All @@ -99,7 +99,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
// File will be written on first write operation.
return this.createDatabaseConnectionWithImport();
}
}
}
else {
// browser
// fileNameOrLocalStorageOrData should be a local storage / indexedDB key
Expand All @@ -113,7 +113,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
} else {
localStorageContent = PlatformTools.getGlobalVariable().localStorage.getItem(fileNameOrLocalStorageOrData);
}

if (localStorageContent != null) {
// localStorage value exists.
return this.createDatabaseConnectionWithImport(JSON.parse(localStorageContent));
Expand Down Expand Up @@ -143,7 +143,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
if (!location && !this.options.location) {
throw new Error(`No location is set, specify a location parameter or add the location option to your configuration`);
}

let path = "";
if (location) {
path = location;
Expand All @@ -154,7 +154,7 @@ export class SqljsDriver extends AbstractSqliteDriver {

if (PlatformTools.type === "node") {
try {
const content = new Buffer(this.databaseConnection.export());
const content = Buffer.from(this.databaseConnection.export());
await PlatformTools.writeFile(path, content);
}
catch (e) {
Expand Down Expand Up @@ -193,7 +193,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
}
}
}

/**
* Returns the current database as Uint8Array.
*/
Expand Down Expand Up @@ -284,4 +284,4 @@ export class SqljsDriver extends AbstractSqliteDriver {
}
}
}
}
}
Expand Up @@ -48,9 +48,9 @@ describe("database schema > column types > mssql", () => { // https://github.com
post.nchar = "A";
post.nvarchar = "This is nvarchar";
post.ntext = "This is ntext";
post.binary = new Buffer("A");
post.varbinary = new Buffer("B");
post.image = new Buffer("This is image");
post.binary = Buffer.from("A");
post.varbinary = Buffer.from("B");
post.image = Buffer.from("This is image");
post.dateObj = new Date();
post.date = "2017-06-21";
post.datetime = new Date();
Expand Down Expand Up @@ -182,8 +182,8 @@ describe("database schema > column types > mssql", () => { // https://github.com
post.varchar = "This is varchar";
post.nchar = "AAA";
post.nvarchar = "This is nvarchar";
post.binary = new Buffer("AAAAA");
post.varbinary = new Buffer("BBBBB");
post.binary = Buffer.from("AAAAA");
post.varbinary = Buffer.from("BBBBB");
post.datetime2 = new Date();
post.time = new Date();
post.datetimeoffset = new Date();
Expand Down Expand Up @@ -252,7 +252,7 @@ describe("database schema > column types > mssql", () => { // https://github.com
post.id = 1;
post.name = "Post";
post.bit = true;
post.binary = new Buffer("A");
post.binary = Buffer.from("A");
post.datetime = new Date();
post.datetime.setMilliseconds(0); // set milliseconds to zero because the SQL Server datetime type only has a 1/300 ms (~3.33̅ ms) resolution
await postRepository.save(post);
Expand Down
Expand Up @@ -61,12 +61,12 @@ describe("database schema > column types > mysql", () => {
post.timestamp.setMilliseconds(0); // set milliseconds to zero, because if datetime type specified without precision, milliseconds won't save in database
post.time = "15:30:00";
post.year = 2017;
post.binary = new Buffer("A");
post.varbinary = new Buffer("B");
post.blob = new Buffer("This is blob");
post.tinyblob = new Buffer("This is tinyblob");
post.mediumblob = new Buffer("This is mediumblob");
post.longblob = new Buffer("This is longblob");
post.binary = Buffer.from("A");
post.varbinary = Buffer.from("B");
post.blob = Buffer.from("This is blob");
post.tinyblob = Buffer.from("This is tinyblob");
post.mediumblob = Buffer.from("This is mediumblob");
post.longblob = Buffer.from("This is longblob");
post.geometry = "POINT(1 1)";
post.point = "POINT(1 1)";
post.linestring = "LINESTRING(0 0,1 1,2 2)";
Expand Down Expand Up @@ -278,7 +278,7 @@ describe("database schema > column types > mysql", () => {
post.id = 1;
post.name = "Post";
post.boolean = true;
post.blob = new Buffer("A");
post.blob = Buffer.from("A");
post.datetime = new Date();
post.datetime.setMilliseconds(0); // set milliseconds to zero, because if datetime type specified without precision, milliseconds won't save in database
await postRepository.save(post);
Expand Down
Expand Up @@ -43,7 +43,7 @@ describe("database schema > column types > oracle", () => {
post.varchar2 = "This is varchar2";
post.nvarchar2 = "This is nvarchar2";
post.long = "This is long";
post.raw = new Buffer("This is raw");
post.raw = Buffer.from("This is raw");
post.dateObj = new Date();
post.date = "2017-06-21";
post.timestamp = new Date();
Expand All @@ -52,7 +52,7 @@ describe("database schema > column types > oracle", () => {
post.timestampWithTimeZone.setMilliseconds(0);
post.timestampWithLocalTimeZone = new Date();
post.timestampWithLocalTimeZone.setMilliseconds(0);
post.blob = new Buffer("This is blob");
post.blob = Buffer.from("This is blob");
post.clob = "This is clob";
post.nclob = "This is nclob";
post.simpleArray = ["A", "B", "C"];
Expand Down Expand Up @@ -137,7 +137,7 @@ describe("database schema > column types > oracle", () => {
post.nchar = "AAA";
post.varchar2 = "This is varchar";
post.nvarchar2 = "This is nvarchar";
post.raw = new Buffer("This is raw");
post.raw = Buffer.from("This is raw");
post.timestamp = new Date();
post.timestampWithTimeZone = new Date();
post.timestampWithLocalTimeZone = new Date();
Expand Down Expand Up @@ -204,7 +204,7 @@ describe("database schema > column types > oracle", () => {
post.id = 1;
post.name = "Post";
post.boolean = true;
post.blob = new Buffer("This is blob");
post.blob = Buffer.from("This is blob");
post.datetime = new Date();
await postRepository.save(post);

Expand Down
Expand Up @@ -48,7 +48,7 @@ describe("database schema > column types > postgres", () => {
post.text = "This is text";
post.citext = "This is text";
post.hstore = "name => Alice, surname => A, age => 30";
post.bytea = new Buffer("This is bytea");
post.bytea = Buffer.from("This is bytea");
post.date = "2017-06-21";
post.interval = "1 year 2 months 3 days 4 hours 5 minutes 6 seconds";
post.time = "15:30:00";
Expand Down
Expand Up @@ -54,12 +54,12 @@ describe("database schema > column types > sap", () => {
post.timestamp.setMilliseconds(0);
post.seconddate = new Date();
post.seconddate.setMilliseconds(0);
post.blob = new Buffer("This is blob");
post.blob = Buffer.from("This is blob");
post.clob = "This is clob";
post.nclob = "This is nclob";
post.boolean = true;
// post.array = ["A", "B", "C"]; // TODO
post.varbinary = new Buffer("This is varbinary");
post.varbinary = Buffer.from("This is varbinary");
post.simpleArray = ["A", "B", "C"];
await postRepository.save(post);

Expand Down Expand Up @@ -187,7 +187,7 @@ describe("database schema > column types > sap", () => {
post.id = 1;
post.name = "Post";
post.boolean = true;
post.blob = new Buffer("This is blob");
post.blob = Buffer.from("This is blob");
post.timestamp = new Date();
await postRepository.save(post);

Expand Down
Expand Up @@ -42,7 +42,7 @@ describe("database schema > column types > sqlite", () => {
post.nchar = "This is nchar";
post.nativeCharacter = "This is native character";
post.nvarchar = "This is nvarchar";
post.blob = new Buffer("This is blob");
post.blob = Buffer.from("This is blob");
post.clob = "This is clob";
post.text = "This is text";
post.real = 10.5;
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("database schema > column types > sqlite", () => {
post.id = 1;
post.name = "Post";
post.boolean = true;
post.blob = new Buffer("A");
post.blob = Buffer.from("A");
post.datetime = new Date();
post.datetime.setMilliseconds(0);
await postRepository.save(post);
Expand Down

0 comments on commit f6bb324

Please sign in to comment.