New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@contentrain/query

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentrain/query

Query builder for Contentrain SDK.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-90.48%
Maintainers
0
Weekly downloads
 
Created
Source

@contentrain/query

Query builder for Contentrain SDK.

Installation

npm install @contentrain/query @contentrain/core

Usage

import { ContentrainCore } from '@contentrain/core'
import { ContentrainQuery } from '@contentrain/query'

// Initialize core and query
const core = new ContentrainCore()
const query = new ContentrainQuery(core)

// Basic query
const posts = await query
  .from('posts')
  .where('status', 'publish')
  .get()

// Complex query
const featuredPosts = await query
  .from('posts')
  .where('status', 'publish')
  .where('featured', true)
  .orderBy('createdAt', 'desc')
  .limit(5)
  .get()

// Query with relations
const postsWithAuthor = await query
  .from('posts')
  .with('author')
  .where('status', 'publish')
  .get()

// Query with multiple conditions
const searchPosts = await query
  .from('posts')
  .where([
    ['status', 'publish'],
    ['category', 'technology'],
    ['title', 'startsWith', 'How to']
  ])
  .get()

API Reference

Constructor

constructor(core: ContentrainCore)

Creates a new instance of ContentrainQuery.

Methods

from
from(collection: string): ContentrainQuery

Specifies the collection to query.

where
where(field: string, value: any): ContentrainQuery
where(field: string, operator: FilterOperator, value: any): ContentrainQuery
where(conditions: [string, any][] | [string, FilterOperator, any][]): ContentrainQuery

Adds where conditions to the query.

orderBy
orderBy(field: string, direction: 'asc' | 'desc' = 'asc'): ContentrainQuery

Orders the results by a field.

limit
limit(count: number): ContentrainQuery

Limits the number of results.

offset
offset(count: number): ContentrainQuery

Skips the specified number of results.

with
with(...relations: string[]): ContentrainQuery

Includes related content in the results.

get
get<T>(): Promise<T[]>

Executes the query and returns the results.

Filter Operators

  • equals (default)
  • notEquals
  • contains
  • notContains
  • startsWith
  • endsWith
  • exists
  • notExists
  • gt (greater than)
  • gte (greater than or equal)
  • lt (less than)
  • lte (less than or equal)

License

MIT

FAQs

Package last updated on 05 Jan 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc