| title | Data Access |
|---|---|
| description | Learn how to query and access data using ObjectQL's type-safe SDK and JSON-based protocol |
ObjectQL provides powerful data access capabilities through a JSON-based Protocol that works seamlessly across different database backends. Unlike SQL strings or Query Builders, ObjectQL queries are structured data that are type-safe, serializable, and perfect for AI agents.
The data access layer in ObjectQL is designed to be:
- Type-Safe: Full TypeScript support with auto-generated types from your schema
- Database Agnostic: The same query works on MongoDB, PostgreSQL, SQLite, and more
- AI-Friendly: Structured JSON format prevents hallucinations and syntax errors
- Serializable: Queries can be sent over HTTP, stored in files, or logged for debugging
Learn the fundamentals of querying data with ObjectQL:
- Find operations and filters
- Sorting and pagination
- Field selection and data expansion
- Aggregations and grouping
- Complex queries with nested conditions
Use the TypeScript SDK for type-safe data access:
- Installation and setup
- Basic CRUD operations
- Advanced querying techniques
- Error handling
- TypeScript integration
Optimize your queries for performance:
- Query optimization strategies
- Avoiding N+1 problems
- Efficient data loading
- Caching strategies
- Performance benchmarks
import { ObjectQL } from '@objectql/core';
// Initialize ObjectQL
const app = new ObjectQL({
datasources: {
default: driver
}
});
await app.init();
const ctx = app.createContext({ isSystem: true });
// Query data with filters
const products = await ctx.object('product').find({
fields: ['name', 'price', 'category'],
filters: [
['category', '=', 'electronics'],
'and',
['price', '<', 1000]
],
sort: [['price', 'asc']],
top: 10
});
console.log('Products:', products);All queries in ObjectQL follow a consistent JSON structure:
{
"op": "find",
"object": "product",
"args": {
"fields": ["name", "price"],
"filters": [["category", "=", "electronics"]],
"top": 10
}
}This structure makes it easy for frontends, AI agents, and external systems to generate safe, valid queries.
- Start with Querying Data to learn the basics
- Explore the Client SDK for type-safe access
- Review Best Practices for optimization strategies
- Check the API Reference for complete documentation