milodb 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/milodb.js +10 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "milodb",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "src/milodb.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/src/milodb.js CHANGED
@@ -10,14 +10,19 @@ class MiloDB {
10
10
  fs.ensureDirSync(this.dbPath); // Ensure that the DB path exists
11
11
  }
12
12
 
13
- // Create a new table (i.e., a new JSON file)
14
13
  async createTable(tableName) {
15
14
  const tablePath = path.join(this.dbPath, `${tableName}.json`);
16
- if (fs.existsSync(tablePath)) {
17
- throw new Error(`Table ${tableName} already exists.`);
15
+
16
+ try {
17
+ if (fs.existsSync(tablePath)) {
18
+ throw new Error(`Table ${tableName} already exists.`);
19
+ }
20
+ await fs.writeJson(tablePath, [], { spaces: 2 });
21
+ console.log(`Table ${tableName} created successfully.`);
22
+ } catch (err) {
23
+ console.error(`Failed to create table: ${err.message}`);
24
+ // Additional logic, like suggesting to delete/rename the table, can go here
18
25
  }
19
- await fs.writeJson(tablePath, [], { spaces: 2 });
20
- console.log(`Table ${tableName} created successfully.`);
21
26
  }
22
27
 
23
28
  // Add a record to a table