Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext IOS Docs CRUD

From Leeroopedia
Knowledge Sources
Domains CRUD, SQLite, iOS
Last Updated 2026-10-24 00:00 GMT

Overview

Document CRUD operations for the iOS app, managing markdown files on the Expo filesystem with SQLite metadata tracking and UUID stable IDs.

Description

The docs.js module in src-ios/db/ provides six async functions for document management: listDocs (queries all docs ordered by updated_at), getDocById (fetches a single doc by ID), createDoc (writes a markdown file to the docs root and inserts a DB row with a generated stable_id), updateDoc (updates file content and DB metadata), deleteDoc (removes DB row and file), and loadDocContent (reads file content from disk). Helper functions buildDocFilename (slugifies title with timestamp suffix), extractDescription (first non-empty line truncated to 160 chars), and normalizeTitle ensure consistent metadata.

Usage

Import these functions in iOS screen components (DocEditorScreen, DocsScreen) to list, create, edit, and delete documents.

Code Reference

Source Location

Signature

async function listDocs() // → Array<DocRow>
async function getDocById(id) // → DocRow | null
async function createDoc({ title, content }) // → DocRow
async function updateDoc({ id, title, content }) // → DocRow | null
async function deleteDoc(id) // → boolean
async function loadDocContent(doc) // → string

Import

const { listDocs, getDocById, createDoc, updateDoc, deleteDoc, loadDocContent } = require('./db/docs');

I/O Contract

Inputs

Name Type Required Description
title String Yes (create/update) Document title
content String No Markdown content
id Number Yes (get/update/delete) Document database ID

Outputs

Name Type Description
DocRow Object { id, name, rel_path, abs_path, description, stable_id, created_at, updated_at }

Usage Examples

Create and List Documents

const { createDoc, listDocs } = require('./db/docs');

// Create a new document
const doc = await createDoc({
  title: 'My First Note',
  content: '# Hello World\n\nThis is my first note.'
});
console.log(doc.id, doc.stable_id);

// List all documents
const allDocs = await listDocs();
allDocs.forEach(d => console.log(d.name, d.updated_at));

Update and Delete

const { updateDoc, deleteDoc, loadDocContent } = require('./db/docs');

// Load content
const content = await loadDocContent(doc);

// Update document
const updated = await updateDoc({ id: doc.id, title: 'Updated Title', content: 'New content' });

// Delete document
const ok = await deleteDoc(doc.id);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment