0.2.3 • Published 8 months ago

@queryleaf/server v0.2.3

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
8 months ago

Overview

@queryleaf/server provides a REST API server for QueryLeaf, allowing you to execute SQL queries against MongoDB through HTTP requests. It's built on Express.js and leverages the core @queryleaf/lib package to parse SQL, transform it into MongoDB commands, and execute those commands.

Installation

# Global installation
npm install -g @queryleaf/server
# or
yarn global add @queryleaf/server

# Local installation
npm install @queryleaf/server
# or
yarn add @queryleaf/server

Usage

Running the Server

# Start the server with default settings
queryleaf-server

# With specific MongoDB URI and port
queryleaf-server --uri mongodb://localhost:27017 --port 3000

# With authentication
queryleaf-server --uri mongodb://user:pass@localhost:27017

# Help
queryleaf-server --help

API Endpoints

Execute SQL Query

POST /api/query

Request body:

{
  "database": "mydb",
  "query": "SELECT * FROM users WHERE age > 21"
}

Response:

{
  "results": [
    { "name": "Alice", "age": 25, "email": "alice@example.com" },
    { "name": "Bob", "age": 30, "email": "bob@example.com" }
  ],
  "count": 2,
  "message": "Query executed successfully"
}

Get Server Information

GET /api/info

Response:

{
  "version": "0.1.0",
  "name": "QueryLeaf Server",
  "mongodb": {
    "connected": true,
    "version": "6.0.0"
  }
}

Configuration

You can configure the server using command-line arguments or environment variables:

ArgumentEnvironment VariableDescription
--uriMONGODB_URIMongoDB connection URI
--portPORTServer port (default: 3000)
--hostHOSTServer host (default: 0.0.0.0)
--corsENABLE_CORSEnable CORS (default: true)
--rate-limitRATE_LIMITRate limit (reqs/min, default: 60)

Security

The server includes security features:

  • Rate limiting to prevent abuse
  • Helmet.js for HTTP security headers
  • Express security best practices
  • Optional authentication

Links

License

QueryLeaf is dual-licensed:

For commercial licensing options, visit queryleaf.com.