@hedystia/db 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -26,7 +26,9 @@ export default class DataBase {
26
26
  };
27
27
  constructor(filePath: string, password: string);
28
28
  createTable(tableName: string, columns: string[]): void;
29
+ createTableIfNotExists(tableName: string, columns: string[]): void;
29
30
  deleteTable(tableName: string): void;
31
+ deleteTableIfExists(tableName: string): void;
30
32
  addColumn(tableName: string, column: string, defaultValue: any): void;
31
33
  deleteColumn(tableName: string, column: string): void;
32
34
  insert(tableName: string, record: {
package/index.js CHANGED
@@ -22,6 +22,14 @@ const Database = class {
22
22
  this.saveToFile();
23
23
  }
24
24
 
25
+ createTableIfNotExists(tableName, columns) {
26
+ this.readFromFile();
27
+ if (!this.tables[tableName]) {
28
+ this.tables[tableName] = { columns, records: [] };
29
+ this.saveToFile();
30
+ }
31
+ }
32
+
25
33
  deleteTable(tableName) {
26
34
  this.readFromFile();
27
35
  if (!this.tables[tableName]) {
@@ -32,6 +40,14 @@ const Database = class {
32
40
  this.saveToFile();
33
41
  }
34
42
 
43
+ deleteTableIfExists(tableName) {
44
+ this.readFromFile();
45
+ if (this.tables[tableName]) {
46
+ delete this.tables[tableName];
47
+ this.saveToFile();
48
+ }
49
+ }
50
+
35
51
  addColumn(tableName, column, defaultValue) {
36
52
  this.readFromFile();
37
53
  if (!this.tables[tableName]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hedystia/db",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "A database made by the company hedystia, easy to use",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/readme.md CHANGED
@@ -80,13 +80,15 @@ console.log(users3);
80
80
 
81
81
  ## Functions
82
82
 
83
- | Function | Description |
84
- | -------------- | ---------------------------------------------- |
85
- | `createTable` | To create a table |
86
- | `deleteTable` | To delete a table |
87
- | `addColumn` | To add a column to an already created table |
88
- | `deleteColumn` | To remove a column to an already created table |
89
- | `insert` | To insert a data in the table |
90
- | `update` | To update a data in the table |
91
- | `select` | To search for information in a table |
92
- | `delete` | To delete a data from the table |
83
+ | Function | Description |
84
+ | ------------------------ | ---------------------------------------------- |
85
+ | `createTable` | To create a table |
86
+ | `deleteTable` | To delete a table |
87
+ | `createTableIfNotExists` | To create a table if it does not exist |
88
+ | `deleteTableIfExists` | To delete a table if it exists |
89
+ | `addColumn` | To add a column to an already created table |
90
+ | `deleteColumn` | To remove a column to an already created table |
91
+ | `insert` | To insert a data in the table |
92
+ | `update` | To update a data in the table |
93
+ | `select` | To search for information in a table |
94
+ | `delete` | To delete a data from the table |