Introduction to HarperDB
HarperDB is a powerful database solution designed to simplify application development by providing a seamless integration of SQL and NoSQL functionalities. It supports RESTful APIs that allow developers to perform a wide range of operations easily and efficiently.
Getting Started with HarperDB
Before diving into the APIs, ensure you have an instance of HarperDB running. You can run it locally or use their cloud service.
Useful API Examples
Create Schema
POST /create_schema {
"schema": "dev"
}
Create Table
POST /create_table {
"schema": "dev",
"table": "users",
"hash_attribute": "user_id"
}
Insert Record
POST /insert {
"schema": "dev",
"table": "users",
"records": [
{
"user_id": 1,
"name": "John Doe",
"email": "john.doe@example.com"
}
]
}
Update Record
POST /update {
"schema": "dev",
"table": "users",
"records": [
{
"user_id": 1,
"name": "John Smith",
"email": "john.smith@example.com"
}
]
}
Delete Record
POST /delete {
"schema": "dev",
"table": "users",
"hash_values": [1]
}
SQL Query
POST /sql {
"sql": "SELECT * FROM dev.users"
}
Perform Custom Functions
POST /custom_function {
"function_name": "getUserByEmail",
"params": {
"email": "john.smith@example.com"
}
}
Application Example
Below is an example of a simple Node.js application that interacts with HarperDB using the above APIs:
Node.js Code Example
const axios = require('axios');
const baseURL = 'http://localhost:9925';
const createUser = async () => {
const response = await axios.post(`${baseURL}/insert`, {
schema: 'dev',
table: 'users',
records: [
{
user_id: 1,
name: 'John Doe',
email: 'john.doe@example.com'
}
]
});
console.log(response.data);
};
createUser();
This application sends a request to insert a new user into the database. You can expand this by adding functions for updating, deleting, and retrieving records based on the examples provided above.
Hash: 24cbe732c63f517d7c392ff642ffcfe5ba132f14b60d11f9b4460d9f875420eb