jsondb-client
Advanced tools
Comparing version
{ | ||
"name": "jsondb-client", | ||
"version": "1.0.10", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
418
README.md
@@ -1,24 +0,404 @@ | ||
const jsondb = require('jsondb'); | ||
Here’s the updated README with the correct database name `jsondb-yu03`: | ||
// Connect with username and password | ||
jsondb.connect('myUsername', 'myPassword'); | ||
--- | ||
// Find a document by one parameter | ||
jsondb.findByOne('myDb', 'myCollection', { key: 'value' }) | ||
.then(data => console.log(data)) | ||
.catch(err => console.error(err)); | ||
# jsondb-client | ||
// Find by ID | ||
jsondb.findById('myDb', 'myCollection', '12345') | ||
.then(data => console.log(data)) | ||
.catch(err => console.error(err)); | ||
`jsondb-client` is a server-based JSON database package designed for easy and secure CRUD operations using API requests. The database can be hosted anywhere securely with limits and custom authentication. The UI for the client is under development using Electron.js. | ||
// Update by ID | ||
jsondb.updateById('myDb', 'myCollection', '12345', { key: 'newValue' }) | ||
.then(response => console.log(response)) | ||
.catch(err => console.error(err)); | ||
## Overview | ||
// Delete by ID | ||
jsondb.deleteById('myDb', 'myCollection', '12345') | ||
.then(response => console.log('Deleted:', response)) | ||
.catch(err => console.error(err)); | ||
`jsondb-client` provides a simple and efficient way to interact with JSON databases similar to traditional MongoDB, but using the `jsondb-yu03` server. This package allows you to manage your databases securely and with custom authentication, enabling you to host and manage your data effectively. | ||
**Note:** The server-side operations are private and protected to prevent theft or unauthorized access. Ensure that your server configurations and credentials are kept secure to prevent any potential misuse. | ||
## Installation | ||
Install via npm: | ||
```bash | ||
npm install jsondb-client | ||
``` | ||
## Usage | ||
### Import and Setup | ||
```javascript | ||
const dbClient = require("jsondb-client"); | ||
const db = dbClient.setConnection({ | ||
server: 'https://jsondb-yu03.onrender.com', | ||
username: 'testuser.com', | ||
password: '370149ecaf812899', | ||
database: 'jsondb-yu03' | ||
}); | ||
const collection = db.Collection('fun'); | ||
``` | ||
## Methods | ||
### `create(data)` | ||
Creates a new document in the specified collection. | ||
#### Example: | ||
```javascript | ||
const result = await collection.create({ name: "John Doe", age: 30 }); | ||
console.log(result); | ||
``` | ||
### `find(query)` | ||
Finds all documents matching the query. | ||
#### Example: | ||
```javascript | ||
const results = await collection.find({ age: { $gt: 20 } }); | ||
console.log(results); | ||
``` | ||
### `findOne(query)` | ||
Finds a single document matching the query. | ||
#### Example: | ||
```javascript | ||
const result = await collection.findOne({ name: "John Doe" }); | ||
console.log(result); | ||
``` | ||
### `findById(id)` | ||
Finds a document by its unique ID. | ||
#### Example: | ||
```javascript | ||
const result = await collection.findById("12345"); | ||
console.log(result); | ||
``` | ||
### `save(data)` | ||
Creates or updates a document based on the provided data. | ||
#### Example: | ||
```javascript | ||
const result = await collection.save({ _id: "12345", name: "Jane Doe" }); | ||
console.log(result); | ||
``` | ||
### `update(id, data)` | ||
Updates a document by its ID. | ||
#### Example: | ||
```javascript | ||
const result = await collection.update("12345", { age: 31 }); | ||
console.log(result); | ||
``` | ||
### `updateOne(query, data)` | ||
Updates a single document matching the query. | ||
#### Example: | ||
```javascript | ||
const result = await collection.updateOne({ name: "John Doe" }, { age: 31 }); | ||
console.log(result); | ||
``` | ||
### `updateMany(query, data)` | ||
Updates multiple documents matching the query. | ||
#### Example: | ||
```javascript | ||
const result = await collection.updateMany({ age: { $lt: 30 } }, { active: false }); | ||
console.log(result); | ||
``` | ||
### `findByIdAndUpdate(id, data)` | ||
Finds a document by ID and updates it. | ||
#### Example: | ||
```javascript | ||
const result = await collection.findByIdAndUpdate("12345", { age: 31 }); | ||
console.log(result); | ||
``` | ||
### `findOneAndUpdate(query, data)` | ||
Finds a single document matching the query and updates it. | ||
#### Example: | ||
```javascript | ||
const result = await collection.findOneAndUpdate({ name: "John Doe" }, { age: 31 }); | ||
console.log(result); | ||
``` | ||
### `deleteOne(query)` | ||
Deletes a single document matching the query. | ||
#### Example: | ||
```javascript | ||
const result = await collection.deleteOne({ name: "John Doe" }); | ||
console.log(result); | ||
``` | ||
### `deleteMany(query)` | ||
Deletes multiple documents matching the query. | ||
#### Example: | ||
```javascript | ||
const result = await collection.deleteMany({ age: { $lt: 30 } }); | ||
console.log(result); | ||
``` | ||
### `findByIdAndDelete(id)` | ||
Finds a document by ID and deletes it. | ||
#### Example: | ||
```javascript | ||
const result = await collection.findByIdAndDelete("12345"); | ||
console.log(result); | ||
``` | ||
### `findOneAndDelete(query)` | ||
Finds a single document matching the query and deletes it. | ||
#### Example: | ||
```javascript | ||
const result = await collection.findOneAndDelete({ name: "John Doe" }); | ||
console.log(result); | ||
``` | ||
### `countDocuments(query)` | ||
Counts the number of documents matching the query. | ||
#### Example: | ||
```javascript | ||
const count = await collection.countDocuments({ active: true }); | ||
console.log(count); | ||
``` | ||
### `distinct(field, query)` | ||
Finds distinct values for a specified field. | ||
#### Example: | ||
```javascript | ||
const values = await collection.distinct("age", { active: true }); | ||
console.log(values); | ||
``` | ||
### `aggregate(pipeline)` | ||
Performs an aggregation operation. | ||
#### Example: | ||
```javascript | ||
const results = await collection.aggregate([{ $match: { active: true } }]); | ||
console.log(results); | ||
``` | ||
### `populate(path, query)` | ||
Populates a field by joining related data. | ||
#### Example: | ||
```javascript | ||
const result = await collection.populate("user", { active: true }); | ||
console.log(result); | ||
``` | ||
### `exec(command, params)` | ||
Executes a custom command with parameters. | ||
#### Example: | ||
```javascript | ||
const result = await collection.exec("customCommand", { param1: "value1" }); | ||
console.log(result); | ||
``` | ||
## Additional Operations | ||
### Delete User | ||
To delete a user, make a `DELETE` request to the `/delete-user` endpoint. | ||
**Request:** | ||
```http | ||
DELETE /delete-user | ||
Content-Type: application/json | ||
``` | ||
**Body:** | ||
```json | ||
{ | ||
"username": "user_to_delete" | ||
} | ||
``` | ||
**Response:** | ||
```json | ||
{ | ||
"message": "User deleted successfully" | ||
} | ||
``` | ||
**Error Response:** | ||
```json | ||
{ | ||
"message": "User not found" | ||
} | ||
``` | ||
### Delete a Collection | ||
To delete a collection, make a `DELETE` request to the `/:dbName/:collectionName/delete-collection` endpoint. | ||
**Request:** | ||
```http | ||
DELETE /:dbName/:collectionName/delete-collection | ||
``` | ||
**URL Parameters:** | ||
- `dbName`: The name of the database. | ||
- `collectionName`: The name of the collection to delete. | ||
**Response:** | ||
```json | ||
{ | ||
"message": "Collection 'collectionName' deleted successfully" | ||
} | ||
``` | ||
**Error Response:** | ||
```json | ||
{ | ||
"message": "Collection not found" | ||
} | ||
``` | ||
### Delete a Database | ||
To delete a database, make a `DELETE` request to the `/delete-db/:dbName` endpoint. | ||
**Request:** | ||
```http | ||
DELETE /delete-db/:dbName | ||
``` | ||
**URL Parameters:** | ||
- `dbName`: The name of the database to delete. | ||
**Response:** | ||
```json | ||
{ | ||
"message": "Database 'dbName' deleted successfully" | ||
} | ||
``` | ||
**Error Response:** | ||
```json | ||
{ | ||
"message": "Database not found" | ||
} | ||
``` | ||
## Authentication and Setup | ||
### Creating New Credentials | ||
To create new credentials, use the following `curl` command: | ||
```bash | ||
curl --location 'https://jsondb-yu03.onrender.com/register' \ | ||
--header 'Content-Type: application/json' \ | ||
--header 'Authorization: Basic bWFub2pnb3dkYWJyODkuY29tOmZmNzkwNTU1Zjk3YTZkNzc=' \ | ||
--data '{ | ||
"email": "testuser.com" | ||
}' | ||
``` | ||
**Response:** | ||
```json | ||
{ | ||
"message": "User registered successfully", | ||
"username": "testuser.com", | ||
"password": "370149ecaf812899" | ||
} | ||
``` | ||
### Creating a Database | ||
To create a database, use the following `curl` command: | ||
```bash | ||
curl --location 'https://jsondb-yu03.onrender.com/add-database' \ | ||
--header 'Authorization: Basic dGVzdHVzZXIuY29tOjM3MDE0OWVjYWY4MTI4OTk=' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"database":"jsondb-yu03" | ||
}' | ||
``` | ||
**Response:** | ||
```json | ||
{ | ||
"message": "Database added successfully", | ||
"databases": [ | ||
"jsondb-yu03" | ||
] | ||
} | ||
``` | ||
### Creating a Collection | ||
To create a collection, use the following `curl` command: | ||
```bash | ||
curl --location --request POST 'https://jsondb-yu03.onrender.com/jsondb-yu03/testcollection' \ | ||
--header 'Authorization: Basic dGVzdHVzZXIuY29tOjM3MDE0OWVjYWY4MTI4OTk=' \ | ||
--header 'Content-Type: application/json' | ||
``` | ||
**Response:** | ||
```json | ||
{ | ||
"message": "Collection created successfully", | ||
"collection": "testcollection" | ||
} | ||
``` | ||
## License | ||
MIT : manojgowdabr89@gmail.com | ||
--- | ||
Feel free to make any additional adjustments or add more details as needed! |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12266
150.74%404
1516%0
-100%