Data Query Model

Understanding the "Atomic Request" Pattern

The code examples provided (Python, Node.js, PHP) are reference wrappers. Unlike traditional databases that maintain a persistent connection and consume RAM 24/7, PON-DB follows a 100% Stateless execution model.

1. Atomic Execution

Each query triggers a dedicated Rust binary instance. It opens the file, performs an O(1) offset jump, decrypts the row, and terminates instantly.

2. Standard Output (STDOUT)

The engine communicates via STDOUT in pure JSON format. This makes it universally compatible with any language that can execute a shell command.

3. Zero Persistence

Once the JSON is delivered to your application, 0 bytes of database memory remain occupied. Your server's RAM stays dedicated only to your business logic.

"Don't build your app around the database. Let the database serve your app only when needed."

Pro Tip: In high-concurrency environments, these wrappers allow you to scale horizontally without worrying about "Max Connections" limits or Deadlocks.


Python


Python Interoperability

Query 20GB Datasets from Python without RAM Overhead

Stop loading massive DataFrames into memory. Use PON-DB as a high-speed filtering layer. Let the Rust engine handle the tO(1) lookup and only bring the relevant JSON objects into your Python environment.

Implementation: The "Glue Code" Pattern
import subprocess
import json

def query_pon(db_path, key_path, query_str):
    """
    Direct bridge to the PON-DB Rust Engine.
    Extremely efficient: Zero RAM overhead in Python.
    """
    cmd = [
        "./pon-db-reader", 
        db_path, 
        "query", 
        query_str, 
        f"--key={key_path}",
        "--nomsg"  # Ensures clean JSON-only output
    ]
    
    try:
        # Execute the atomic binary
        result = subprocess.run(cmd, capture_output=True, text=True, check=True)
        
        if not result.stdout.strip():
            return []

        # Parse each line as a JSON object (Streaming friendly)
        return [json.loads(line) for line in result.stdout.strip().split('\n')]
    
    except (subprocess.CalledProcessError, json.JSONDecodeError):
        return None

# Usage: Fetching specific records in milliseconds
# data = query_pon("big_data.pon", "key.bin", "id=450000")
    
Note: This pattern allows you to run complex queries on low-spec machines where standard Python libraries would crash due to Out-Of-Memory (OOM) errors.

Combine the speed of Rust with the flexibility of Python.

Get the Reader Binaries

Node.js Integration

Asynchronous, Non-blocking Querying for High-Traffic APIs

Leverage Node.js child_process to build ultra-fast APIs. By using PON-DB, your Node server doesn't need to keep massive JSON objects in heap memory, preventing garbage collection spikes and keeping your event loop free.

Implementation: Async Promise Wrapper
const { spawn } = require('child_process');

/**
 * Execute a query on PON-DB and process the JSON stream
 */
function queryPon(dbPath, keyPath, queryStr) {
  return new Promise((resolve, reject) => {
    const results = [];
    const pon = spawn('./pon-db-reader', [
      dbPath, 
      'query', 
      queryStr, 
      `--key=${keyPath}`,
      '--nomsg' // Ensure clean output
    ]);

    pon.stdout.on('data', (data) => {
      const lines = data.toString().trim().split('\n');
      lines.forEach(line => {
        try {
          if (line) results.push(JSON.parse(line));
        } catch (e) { /* Ignore malformed lines */ }
      });
    });

    pon.on('close', (code) => {
      (code === 0) ? resolve(results) : reject(new Error(`Exit code: ${code}`));
    });
  });
}

// --- Usage Example ---
queryPon("data.pon", "key.bin", "id=1")
  .then(data => console.log(data))
  .catch(err => console.error(err));