datastore

datastore is a cursor rule for Cursor from theimaginaryfoundation/what-iff. It costs 0 tokens per session (4,008 once invoked), scanned A, original, Apache-2.0.

Rules for the persistent datastore layer, which is the part of an application that saves and retrieves data, using Ent and Go models.

In plain words
What is it for?
Use them when adding datastore methods, implementing entity access, or changing how the API reads and writes stored data.
Why use it?
They prevent database details from leaking into the rest of the application and keep data access, logging, and file organization consistent.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use them when adding datastore methods, implementing entity access, or changing how the API reads and writes stored data.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/theimaginaryfoundation/what-iff/datastore
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/theimaginaryfoundation/what-iff

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for datastore

README.md
[![agentmods](https://agentmods.dev/badge/rules/theimaginaryfoundation/what-iff/datastore/github.svg)](https://agentmods.dev/rules/theimaginaryfoundation/what-iff/datastore)
Your own site
<a href="https://agentmods.dev/rules/theimaginaryfoundation/what-iff/datastore"><img src="https://agentmods.dev/badge/rules/theimaginaryfoundation/what-iff/datastore/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for datastore

Your own site · 80×15
<a href="https://agentmods.dev/rules/theimaginaryfoundation/what-iff/datastore"><img src="https://agentmods.dev/badge/rules/theimaginaryfoundation/what-iff/datastore.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 4,008 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.04008
Opus 5 $0.00000 $0.02004
Sonnet 5 $0.00000 $0.00802
Haiku 4.5 $0.00000 $0.00401

Measured yesterday against content hash 07a5b4031db7, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

datastore scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/datastore.mdc · 599 lines

How it starts

The opening of the file, as written. The whole thing — 599 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Datastore Implementation Guidelines

Overview

Our datastore layer uses Ent as the ORM and follows consistent patterns for data access. This document outlines the key patterns and best practices to follow when working with the datastore package.

General Architecture

  • Package: All datastore code lives in the internal/datastore package
  • Models: We use models from the internal/models package for input/output, never exposing Ent types directly
  • Client: The datastore uses an Ent client for database operations
  • Logging: We use zap.Logger for structured logging throughout the datastore
// Base Datastore struct
type Datastore struct {
    dbClient *ent.Client
    logger   *zap.Logger
}

func NewDatastore(dbClient *ent.Client, logger *zap.Logger) *Datastore {
    return &Datastore{
        dbClient: dbClient,
        logger:   logger,
    }
}

File Organization

Each entity type should have its own file in the datastore package. For example:

  • content_idea.go - Content idea based on trending news and posts related to a niche
  • content_brief.go - A content development brief including SEO plan
  • interview_question.go - An interview question and the user's response for content development

Standard Methods

Each entity type should implement the following standard methods:

  1. Model Conversion Function: Convert from Ent type to model type
// Convert from Ent entity to model
func toContentIdeaModel(e *ent.ContentIdea) *models.ContentIdea {
    return &models.ContentIdea{
        ID:        e.ID,
        ProjectID: e.Edges.Project.ID,
        Title:     e.Title,
        Summary:   e.Summary,
        SourceURL: e.SourceURL,
        Approved:  e.Approved,
        CreatedAt: e.CreatedAt,
        UpdatedAt: e.UpdatedAt,
    }
}
  1. Create Method: Single entity creation with transaction and authorization
func (d *Datastore) CreateContentIdea(ctx context.Context, userID uuid.UUID, contentIdea models.ContentIdea) (*models.ContentIdea, error) {
    // Start transaction
    tx, err := d.dbClient.Tx(ctx)
    if err != nil {
        d.logger.Error("failed to start transaction", zap.Error(err))
        return nil, err
    }

    // Rollback in case of error
    defer func() {
        if v := recover(); v != nil {
            tx.Rollback()
            panic(v)
        }
    }()

    // Check if project exists and belongs to the user
    projectExists, err := tx.Project.Query().
        Where(
            project.ID(contentIdea.ProjectID),
            project.HasOwnerWith(
                user.ID(userID),
            ),
        ).
        Exist(ctx)

    if err != nil {
        d.logger.Error("failed to query project", zap.Error(err))
        if rerr := tx.Rollback(); rerr != nil {
            d.logger.Error("failed to rollback transaction", zap.Error(rerr))
        }
        return nil, err
    }

    if !projectExists {
        d.logger.Error("project not found or user not authorized",
            zap.String("project_id", contentIdea.ProjectID.String()),
            zap.String("user_id", userID.String()))
        if rerr := tx.Rollback(); rerr != nil {
            d.logger.Error("failed to rollback transaction", zap.Error(rerr))
        }
        return nil, ErrProjectNotFound
    }

    // Create entity
    entContentIdea, err := tx.ContentIdea.Create().
        SetTitle(contentIdea.Title).
        SetSummary(contentIdea.Summary).
        SetSourceURL(contentIdea.SourceURL).
        SetApproved(contentIdea.Approved).
        SetProjectID(contentIdea.ProjectID).
        Save(ctx)
        
    if err != nil {
        d.logger.Error("failed to create content idea", zap.Error(err))
        if rerr := tx.Rollback(); rerr != nil {
            d.logger.Error("failed to rollback transaction", zap.Error(rerr))
        }
        return nil, err
    }
    
    // Load relationships needed for model conversion
    entContentIdea, err = tx.ContentIdea.Query().
        Where(contentidea.ID(entContentIdea.ID)).
        WithProject().
        Only(ctx)

    if err != nil {
        d.logger.Error("failed to load project relationship", zap.Error(err))
        if rerr := tx.Rollback(); rerr != nil {
            d.logger.Error("failed to rollback transaction", zap.Error(rerr))
        }
        return nil, err
    }
    
    // Commit transaction
    if err := tx.Commit(); err != nil {
        d.logger.Error("failed to commit transaction", zap.Error(err))
        return nil, err
    }
    
    // Return model
    return toContentIdeaModel(entContentIdea), nil
}

Read the full file on GitHub · 599 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 599 lines · 0 tokens per session scan A 07a5b4031db7

Subscribe to this mod's changes

datastore is a cursor rule published in the GitHub repository theimaginaryfoundation/what-iff (15 stars, last pushed today), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 4,008 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-09.