update readme
This commit is contained in:
parent
fcb4a98b32
commit
5893221df7
90
README.md
90
README.md
@ -22,15 +22,101 @@ const datasquirel = require("datasquirel");
|
|||||||
|
|
||||||
### Fetch Data
|
### Fetch Data
|
||||||
|
|
||||||
This method requires a readonly key or fullaccess key gotten from [datasquirel](https://datasquirel.com/). It uses a basic https get request paired with some query params.
|
This method requires a readonly key or fullaccess API key gotten from [datasquirel](https://datasquirel.com/). It uses a basic https get request paired with some query params.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const datasquirel = require("datasquirel");
|
const datasquirel = require("datasquirel");
|
||||||
|
|
||||||
const getData = await datasquirel.get({
|
const getData = await datasquirel.get({
|
||||||
key: "aldhkf89asdflksdafh908asdfjkhasdf", // API Key
|
key: "aldhkf89asdflksdafh908asdfjkhasdf", // Readonly API Key
|
||||||
db: "my_database", // Database name slug (Eg. Db Name => My Database, Db Slug => my_database)
|
db: "my_database", // Database name slug (Eg. Db Name => My Database, Db Slug => my_database)
|
||||||
query: "SELECT * FROM blog_posts", // SQL Query
|
query: "SELECT * FROM blog_posts", // SQL Query
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Datasquirel uses all conventional SQL query commands. However you can only use the `SELECT` command when using a readonly API key.
|
Datasquirel uses all conventional SQL query commands. However you can only use the `SELECT` command when using a readonly API key.
|
||||||
|
|
||||||
|
### Post Data
|
||||||
|
|
||||||
|
This method requires a fullaccess API key gotten from [datasquirel](https://datasquirel.com/). You can perform a basic fetch with this method, as well as more complex operations like `UPDATE`, `DELETE` and `INSERT`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const datasquirel = require("datasquirel");
|
||||||
|
|
||||||
|
const postData = await datasquirel.post({
|
||||||
|
key: "aldhkf89asdflksdafh908asdfjkhasdf", // Fullaccess API Key
|
||||||
|
payload: {
|
||||||
|
action: "insert", // OR "update" OR "delete" OR "select"
|
||||||
|
data: {
|
||||||
|
user_id: "19aisdn123",
|
||||||
|
user_first_name: "John",
|
||||||
|
user_last_name: "Doe",
|
||||||
|
},
|
||||||
|
table: "users",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can simply replace the `payload` object with an SQL string and it does everything you provide in the SQL command.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const datasquirel = require("datasquirel");
|
||||||
|
|
||||||
|
const postData = await datasquirel.post({
|
||||||
|
key: process.env.FULL_ACCESS_API_KEY,
|
||||||
|
payload: "SELECT * FROM blog_posts WHERE user_id='as09d7nasd90'",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can add a condition to the `payload` object to filter the results
|
||||||
|
|
||||||
|
```js
|
||||||
|
const datasquirel = require("datasquirel");
|
||||||
|
|
||||||
|
const postData = await datasquirel.post({
|
||||||
|
key: process.env.FULL_ACCESS_API_KEY,
|
||||||
|
payload: {
|
||||||
|
action: "delete",
|
||||||
|
condition: `WHERE user_id='21adwei9jewr' AND type='buyers'`,
|
||||||
|
table: "users",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use `identifierColumnName` and `identifierValue` when updating an entry.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const datasquirel = require("datasquirel");
|
||||||
|
|
||||||
|
const postData = await datasquirel.post({
|
||||||
|
key: process.env.FULL_ACCESS_API_KEY,
|
||||||
|
payload: {
|
||||||
|
action: "update",
|
||||||
|
table: "users",
|
||||||
|
identifierColumnName: "id",
|
||||||
|
identifierValue: "21adwei9jewr",
|
||||||
|
data: {
|
||||||
|
first_name: "Mary",
|
||||||
|
last_name: "Spencer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Upload Image
|
||||||
|
|
||||||
|
This method requires is similar to the `post` method, but with different parameters.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const datasquirel = require("datasquirel");
|
||||||
|
|
||||||
|
const postData = await datasquirel.post({
|
||||||
|
key: process.env.FULL_ACCESS_API_KEY,
|
||||||
|
payload: {
|
||||||
|
imageData: "6ejsiua2i29ndsajkfn9n==", // Image in base64
|
||||||
|
imageName: `awesome-waterfalls`,
|
||||||
|
mimeType: "jpg", // optional
|
||||||
|
thumbnailSize: 120, // optional === This measurement is in pixels(px)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user