Skip to content

Commit

Permalink
Merge pull request #14 from markwylde/upsert-batchInsert
Browse files Browse the repository at this point in the history
feat: implement upsert; implement batchInsert;
  • Loading branch information
markwylde authored Dec 23, 2024
2 parents 8a1dada + 702b743 commit fa3244d
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 87 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ doubledb.insert({
skills: ['cooking', 'running']
});

doubledb.get(record.id);
doubledb.read(record.id);
doubledb.find('firstName', 'Joe');
doubledb.find('stats.wins', 10);
doubledb.find('skills', 'cooking');
Expand All @@ -34,9 +34,16 @@ doubledb.filter('firstName', v => v.startsWith('J'), { limit: 10, skip: 20, gt:
doubledb.replace(record.id, { firstName: 'Joe', lastName: 'Bloggs' });
doubledb.patch(record.id, { firstName: 'Bob' });
doubledb.remove(record.id);

// Batch insert multiple documents for better performance
doubledb.batchInsert([
{ firstName: 'Alice', lastName: 'Smith' },
{ firstName: 'Bob', lastName: 'Johnson' },
{ firstName: 'Charlie', lastName: 'Brown' }
]);
```

### `.get(id)`
### `.read(id)`
Get a single record by it's `.id` property.

If a record is found, the whole record will be returned.
Expand Down Expand Up @@ -188,3 +195,18 @@ const records = await doubledb.query({
- **$not**: Matches documents that do not match the specified condition.

This query method is powerful and allows combining multiple conditions and operators to fetch the desired records from the database.

### `.batchInsert(documents)`
Insert multiple documents at once for better performance.

**Example:**
```javascript
await doubledb.batchInsert([
{ firstName: 'Alice', lastName: 'Smith' },
{ firstName: 'Bob', lastName: 'Johnson' },
{ firstName: 'Charlie', lastName: 'Brown' }
]);
```

If the documents are successfully inserted, an array of the inserted documents will be returned.
If the documents array is empty, an error will be thrown.
132 changes: 54 additions & 78 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
},
"homepage": "https://github.com/markwylde/doubledb#readme",
"devDependencies": {
"@types/node": "^22.10.1",
"@types/node": "^22.10.2",
"@types/uuid": "^10.0.0",
"c8": "^10.1.2",
"c8": "^10.1.3",
"semistandard": "^17.0.0",
"tsx": "^4.19.2",
"typescript": "^5.7.2"
},
"dependencies": {
"level": "^8.0.1",
"level": "^9.0.0",
"uuid": "^11.0.3"
}
}
Loading

0 comments on commit fa3244d

Please sign in to comment.