
Security News
OpenGrep Restores Fingerprinting in JSON and SARIF Outputs
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
@contentrain/query
Advanced tools
Core package for Contentrain SDK, providing fundamental functionality and types
Core package of the Contentrain SDK. Originally designed for JSON-based content management, now extended with SQLite integration for enhanced performance and scalability.
# Using npm
npm install @contentrain/query
# Using yarn
yarn add @contentrain/query
# Using pnpm
pnpm add @contentrain/query
import { ContentrainSDK } from '@contentrain/query';
// Initialize SDK with JSON files
const sdk = new ContentrainSDK({
contentDir: './content', // Directory containing JSON files
defaultLocale: 'en'
});
// Query JSON content
const posts = await sdk.query('posts')
.where('status', 'eq', 'publish')
.get();
// Load with translations
const trPosts = await sdk.query('posts')
.locale('tr')
.get();
import { SQLiteQueryBuilder, BaseSQLiteLoader } from '@contentrain/query';
// Initialize SQLite loader
const loader = new BaseSQLiteLoader('path/to/database.db');
// Create SQLite query builder
const builder = new SQLiteQueryBuilder('posts', loader);
// Execute SQLite query
const result = await builder
.where('status', 'eq', 'publish')
.get();
// JSON-based relation loading
const posts = await sdk.query('posts')
.include('author')
.get();
interface Post {
id: string;
title: string;
author_id: string;
_relations?: {
author: Author;
categories: Category[];
}
}
// One-to-One in SQLite
const post = await builder
.include('author')
.where('id', 'eq', '123')
.first();
// One-to-Many in SQLite
const postWithCategories = await builder
.include('categories')
.where('id', 'eq', '123')
.first();
// Dedicated translation tables
const trPost = await builder
.locale('tr')
.where('id', 'eq', '123')
.first();
// Fallback support
const result = await builder
.locale('tr')
.include(['author', 'categories'])
.get();
class ContentrainSDK {
constructor(options: ContentLoaderOptions)
query<T extends QueryConfig>(model: string): ContentrainQueryBuilder<T>
load<T>(model: string): Promise<LoaderResult<T>>
}
class SQLiteQueryBuilder<T extends DBRecord> {
constructor(model: string, connection: BaseSQLiteLoader)
// Query Methods
where<K extends keyof T>(
field: K,
operator: Operator,
value: T[K] | T[K][]
): this
include(relations: string | string[]): this
orderBy(field: keyof T, direction?: 'asc' | 'desc'): this
limit(count: number): this
offset(count: number): this
locale(code: string): this
// Execution Methods
get(): Promise<QueryResult<T>>
first(): Promise<T | null>
count(): Promise<number>
}
// ✅ Use JSON when:
// - Small to medium dataset
// - Git-based version control is priority
// - Simple content structure
const posts = await sdk.query('posts').get();
// ✅ Use SQLite when:
// - Large dataset
// - Complex relations
// - Performance is critical
// - Advanced querying needed
const posts = await builder
.where('status', 'eq', 'publish')
.include(['author', 'categories'])
.orderBy('created_at', 'desc')
.limit(10)
.get();
try {
const result = await builder
.where('status', 'eq', 'publish')
.get();
} catch (error) {
if (error instanceof SQLiteError) {
// Handle SQLite specific errors
} else if (error instanceof ValidationError) {
// Handle validation errors
} else if (error instanceof RelationError) {
// Handle relation errors
} else if (error instanceof FileSystemError) {
// Handle JSON file system errors
}
}
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)MIT
FAQs
Core package for Contentrain SDK, providing fundamental functionality and types
The npm package @contentrain/query receives a total of 10 weekly downloads. As such, @contentrain/query popularity was classified as not popular.
We found that @contentrain/query demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.