Skip to Content
ServicesDatabase Services

Database Services

The @orbitusdev/database package provides type-safe database operations with Prisma ORM. All services include caching and multilingual support.

Content Services

Posts

Blog post management with multilingual content support.

Get Post by Slug

import { getPostBySlug } from '@orbitusdev/database'; const post = await getPostBySlug('welcome-to-orbitus', 'tr'); // Returns: PostWithLocale | null

List Published Posts

import { getPublishedPosts } from '@orbitusdev/database'; const posts = await getPublishedPosts({ locale: 'tr', page: 1, limit: 10 }); // Returns: PostListItem[]

Search Posts

import { searchPosts } from '@orbitusdev/database'; const results = await searchPosts('Next.js', 'tr', 10); // Full-text search in titles and content

Create Multilingual Post

import { createMultilingualPost } from '@orbitusdev/database'; const post = await createMultilingualPost({ slug: 'my-awesome-post', authorId: user.id, status: 'PUBLISHED', publishedAt: new Date(), translations: [ { locale: 'tr', title: 'Harika Bir Yazı', content: '# İçerik\n\nMarkdown formatında...', excerpt: 'Kısa özet', coverImage: '/images/cover.jpg', metaTitle: 'SEO Başlık', metaDescription: 'SEO açıklama' }, { locale: 'en', title: 'An Awesome Post', content: '# Content\n\nIn markdown format...', excerpt: 'Short summary', coverImage: '/images/cover.jpg', metaTitle: 'SEO Title', metaDescription: 'SEO description' } ], categoryIds: ['category-id-1'], tagIds: ['tag-id-1', 'tag-id-2'] });

Update Post Translation

import { updatePostTranslation } from '@orbitusdev/database'; const updated = await updatePostTranslation( postId, 'tr', { title: 'Güncellenmiş Başlık', content: 'Yeni içerik...' } );

Get Post Locales

import { getPostLocales } from '@orbitusdev/database'; const locales = await getPostLocales(postId); // Returns: ['tr', 'en']

Categories

Category management with translations.

Get Category by Slug

import { getCategoryBySlug } from '@orbitusdev/database'; const category = await getCategoryBySlug('technology', 'tr'); // Returns: CategoryWithLocale | null

List Categories

import { listCategories } from '@orbitusdev/database'; const categories = await listCategories('tr'); // Returns: CategoryWithLocale[]

Tags

Tag management with translations.

Get Tag by Slug

import { getTagBySlug } from '@orbitusdev/database'; const tag = await getTagBySlug('nextjs', 'tr'); // Returns: TagWithLocale | null

List Tags

import { listTags } from '@orbitusdev/database'; const tags = await listTags('tr'); // Returns: TagWithLocale[]

Pricing Services

Product and subscription plan management with flexible billing types.

Create Subscription Plan

import { createPricingPlan } from '@orbitusdev/database'; const plan = await createPricingPlan({ code: 'pro', billingType: 'SUBSCRIPTION', monthlyPrice: 29.99, yearlyPrice: 299.99, currency: 'USD', featureKeys: ['feature-1', 'feature-2', 'feature-3'], isFeatured: true, sortOrder: 1, status: 'ACTIVE', translations: [ { locale: 'tr', name: 'Pro Plan', description: 'Profesyoneller için', features: ['Sınırsız proje', 'Öncelikli destek', 'Gelişmiş analitik'], badge: 'Popüler' }, { locale: 'en', name: 'Pro Plan', description: 'For professionals', features: ['Unlimited projects', 'Priority support', 'Advanced analytics'], badge: 'Popular' } ] });

Create One-Time Product

import { createPricingPlan } from '@orbitusdev/database'; const product = await createPricingPlan({ code: 'ebook-nextjs', billingType: 'ONE_TIME', oneTimePrice: 49.99, currency: 'USD', coverImage: '/products/ebook-cover.jpg', images: [ '/products/preview-1.jpg', '/products/preview-2.jpg', '/products/preview-3.jpg' ], featureKeys: ['ebook', 'downloadable', 'pdf'], isFeatured: false, sortOrder: 10, translations: [ { locale: 'tr', name: 'Next.js E-Kitap', description: 'Kapsamlı Next.js rehberi', features: ['300+ sayfa', 'Kod örnekleri', 'Ömür boyu erişim'], badge: 'Yeni' }, { locale: 'en', name: 'Next.js E-Book', description: 'Comprehensive Next.js guide', features: ['300+ pages', 'Code examples', 'Lifetime access'], badge: 'New' } ] });

Create Lifetime Product

import { createPricingPlan } from '@orbitusdev/database'; const lifetime = await createPricingPlan({ code: 'lifetime-access', billingType: 'LIFETIME', oneTimePrice: 999.99, currency: 'USD', featureKeys: ['all-features', 'lifetime-updates'], isFeatured: true, sortOrder: 2, translations: [ { locale: 'tr', name: 'Ömür Boyu Erişim', description: 'Tüm özellikler, ömür boyu güncellemeler', features: ['Tüm özellikler', 'Ömür boyu güncelleme', 'Öncelikli destek'], badge: 'En İyi Değer' } ] });

List Plans by Type

import { listPricingPlans, listSubscriptionPlans, listOneTimeProducts, listLifetimeProducts } from '@orbitusdev/database'; // Tüm planları getir const allPlans = await listPricingPlans('tr'); // Sadece abonelikleri getir const subscriptions = await listSubscriptionPlans('tr'); // Sadece tek seferlik ürünleri getir const products = await listOneTimeProducts('tr'); // Sadece lifetime ürünleri getir const lifetime = await listLifetimeProducts('tr');

Get Plan by ID

import { getPricingPlanById } from '@orbitusdev/database'; const plan = await getPricingPlanById('plan-id', 'tr'); // Returns: PricingPlanWithLocale | null

Update Plan

import { updatePricingPlan } from '@orbitusdev/database'; const updated = await updatePricingPlan('plan-id', { monthlyPrice: 39.99, yearlyPrice: 399.99, isFeatured: true, translations: [ { locale: 'tr', name: 'Güncellenmiş Plan', description: 'Yeni açıklama' } ] });

Delete Plan

import { deletePricingPlan } from '@orbitusdev/database'; const deleted = await deletePricingPlan('plan-id'); // Returns the deleted plan with translations

Types

All services return fully typed data structures.

Post Types

import type { PostWithLocale, PostListItem } from '@orbitusdev/database'; // PostWithLocale includes full content // PostListItem excludes full content for performance

Category & Tag Types

import type { CategoryWithLocale, TagWithLocale } from '@orbitusdev/database';

Pricing Types

import type { PricingPlanWithLocale, CreatePlanInput, UpdatePlanInput, PlanTranslationInput, BillingType, PricingPlanStatus } from '@orbitusdev/database'; // BillingType: 'SUBSCRIPTION' | 'ONE_TIME' | 'LIFETIME' // PricingPlanStatus: 'ACTIVE' | 'INACTIVE' | 'ARCHIVED'

Caching

All read operations use Redis caching with configurable TTL:

  • Posts: 5 minutes
  • Categories: 5 minutes
  • Tags: 5 minutes
  • Pricing: Not cached (real-time pricing)

Cache is automatically invalidated on updates.


Best Practices

  1. Always specify locale when fetching localized content
  2. Use pagination for large datasets (page, limit)
  3. Cache at API level for frequently accessed data
  4. Validate prices before creating/updating plans
  5. Use transactions for complex operations
  6. Set appropriate billing types based on product nature
  7. Include cover images for better UX on products

Last updated on