Getting Started with Query-2jz

Learn how to build fast, type-safe APIs with Query-2jz in minutes.

3-5x Faster

Automatic query optimization and built-in caching make Query-2jz significantly faster than GraphQL.

Type Safe

End-to-end TypeScript support with auto-generated types from your data models.

Edge Ready

Optimized for edge functions with minimal cold starts and global distribution.

Zero Setup

No resolvers, no complex configuration. Just define your models and start building.

What is Query-2jz?

Query-2jz is a GraphQL alternative that combines the power of GraphQL with the performance of REST. It provides automatic query optimization, built-in HTTP caching, real-time capabilities, and end-to-end type safety without the complexity of traditional GraphQL implementations.

Key Benefits

  • Automatic Query Optimization: Compiler analyzes queries and generates optimal SQL/NoSQL calls
  • Built-in HTTP Caching: Queries are automatically GET-ified with stable URLs and ETags
  • Real-time by Default: Every query can optionally be "live" with server-pushed updates
  • End-to-End Type Safety: Uses TypeScript AST to generate types from backend to frontend
  • Zero Resolvers: Define data models and relationships, system auto-generates CRUD operations
  • Edge-Ready: Designed to run on edge functions with minimal cold starts

Quick Example

Here's how simple it is to get started with Query-2jz:

1. Define Your Models

javascript
// query-2jz.config.js
module.exports = {
  database: {
    type: 'sqlite',
    connection: './database.sqlite'
  },
  models: [
    {
      name: 'User',
      fields: {
        id: { type: 'id' },
        name: { type: 'string', required: true },
        email: { type: 'string', required: true, unique: true },
        posts: { type: 'relation', model: 'Post', many: true }
      }
    },
    {
      name: 'Post',
      fields: {
        id: { type: 'id' },
        title: { type: 'string', required: true },
        content: { type: 'string' },
        author: { type: 'relation', model: 'User' }
      }
    }
  ]
}

2. Initialize Your Project

bash
# Initialize a new Query-2jz project
npx query-2jz init

# This creates:
# - package.json with scripts
# - query-2jz.config.js with sample models
# - .gitignore file
# - README.md with instructions

3. Start the Development Server

bash
# Start development server
npx query-2jz dev

# Or use the npm script
npm run dev

# Your API will be available at:
# GET  /api/query-2jz/User     - Query users
# POST /api/query-2jz/User     - Create user
# GET  /api/query-2jz/Post     - Query posts
# POST /api/query-2jz/Post     - Create post

Note: The development server is currently in development. The CLI shows a placeholder message for now.

4. Query Your Data

javascript
// Query users with their posts
const users = await fetch('/api/query-2jz/User?include=posts').then(r => r.json())

// Create a new user
const newUser = await fetch('/api/query-2jz/User', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    name: 'John Doe',
    email: 'john@example.com'
  })
}).then(r => r.json())

CLI Usage Examples

Here are some common CLI commands you'll use when working with Query-2jz:

Project Management

bash
# Create a new project
npx query-2jz init my-awesome-app
cd my-awesome-app

# Check CLI version
npx query-2jz --version

# Get help for any command
npx query-2jz --help
npx query-2jz init --help

Development Workflow

bash
# Start development server
npx query-2jz dev

# Start with custom port
npx query-2jz dev --port 3001

# Generate TypeScript types
npx query-2jz generate-types

# Build for production
npx query-2jz build

Using npm Scripts

json
{
  "scripts": {
    "dev": "npx query-2jz dev",
    "build": "npx query-2jz build",
    "generate-types": "npx query-2jz generate-types"
  }
}

After running npx query-2jz init, you can use npm run dev instead of the full CLI commands.

Next Steps

Installation

Learn how to install Query-2jz and set up your first project

Try Playground

Experiment with Query-2jz in our interactive playground