Installation
Install the PingDartDB Node.js SDK via npm:
npm install pingdartdb-node1. Get Your SDK Key
Before initializing the SDK, you need a local SDK key.
- Log in to your PingDart User Dashboard.
- Navigate to Settings > Security.
- Scroll down to the PingDartDB Local SDK Keys section.
- Click Create SDK Key.
- Provide an app name and choose your tier (Free for Local Sync, Pro for Cloud Remote).
- Copy the generated key (e.g.,
pd_...).
2. Initialization
Initialize the SDK with your API key and your local database credentials.
const PingDartDB = require('pingdartdb-node');
const db = new PingDartDB('YOUR_SDK_KEY_HERE', {
host: 'localhost',
user: 'root',
password: 'your_password',
database: 'my_app',
type: 'mysql' // or 'postgres'
});
async function startApp() {
await db.connect();
console.log("Connected to PingDartDB Local!");
}
startApp();3. Reading Data (with Joins & Range)
Use the read() method to fetch data. It supports advanced filtering, pagination, geo-fencing (range), and deeply nested joins (margedata).
const results = await db.table('users').read({
conditions: { status: 'active' },
search: { username: 'john' }, // OR search across specified fields
pagination: { page: 1, limit: 10 },
orderBy: 'created_at DESC',
// Merge related data from other tables (Joins)
margedata: [
{
target_table: 'orders',
target_column: 'user_id',
target_value: 'id',
target_label: 'user_orders',
search_fields: [{ status: 'orders.status' }],
margedata: [
{
target_table: 'order_items',
target_column: 'order_id',
target_value: 'id',
target_label: 'items'
}
]
}
],
// Geospatial search (Haversine formula)
range: {
latitude: 12.97,
longitude: 77.59,
radius: 10, // km
target_latitude: 'lat',
target_longitude: 'lng'
}
});
console.log(results.data);4. Insert, Update, Delete & Count
Insert
// Single Insert
await db.table('users').insert({ name: 'Alice', email: 'alice@example.com' });
// Bulk Insert
await db.table('users').insert([
{ name: 'Bob', email: 'bob@example.com' },
{ name: 'Charlie', email: 'charlie@example.com' }
]);Update
// Update records matching condition
await db.table('users').update({ status: 'active' }, { role: 'admin' });Delete
// Delete records matching condition
await db.table('users').delete({ status: 'banned' });Count
const count = await db.table('users').count({ status: 'active' });
console.log("Total active users:", count);Need more help?
Go to Dashboard