Go to file
2024-07-13 08:35:21 +01:00
client Update media types 2023-12-15 11:08:23 +01:00
engine Add Email Login: Update 2024-07-13 08:09:22 +01:00
functions updates 2023-09-21 15:00:04 +01:00
ssl Bugfix 2024-01-18 16:46:15 +01:00
types Update types 2024-07-13 08:35:21 +01:00
users Add Email Login: Update 2024-07-13 08:09:22 +01:00
utils Add Email Login 2024-07-13 07:23:46 +01:00
.gitignore updates 2023-09-21 15:00:04 +01:00
console-colors.js updates 2023-09-21 15:00:04 +01:00
index.js Add Email Login: Update 2024-07-13 08:09:22 +01:00
package-lock.json Add Email Login 2024-07-13 07:23:46 +01:00
package.json Add Email Login 2024-07-13 07:23:46 +01:00
publish.sh Update media types 2023-12-15 11:08:23 +01:00
push.sh Update media types 2023-12-15 11:08:23 +01:00
README.md Update README: Typo 2024-07-13 07:29:40 +01:00

Datasquirel

This package requires an account with datasquirel, so be sure to create an account at datasquirel-create-account before you continue.

Installation

$ npm install --save https://github.com/BenjaminToby/dsql.git

Once the package is installed, you can import the library using require approach:

const datasquirel = require("datasquirel");

Usage

Fetch Data

This method requires a readonly key or fullaccess API key gotten from datasquirel. It uses a basic https get request paired with some query params.

const datasquirel = require("datasquirel");

const getData = await datasquirel.get({
    key: "aldhkf89asdflksdafh908asdfjkhasdf", // Readonly API Key
    db: "my_database", // Database name slug (Eg. Db Name => My Database, Db Slug => my_database)
    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.

Post Data

This method requires a fullaccess API key gotten from datasquirel. You can perform a basic fetch with this method, as well as more complex operations like UPDATE, DELETE and INSERT.

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.

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

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.

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.

const datasquirel = require("datasquirel");

const postData = await datasquirel.uploadImage({
    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)
    },
});