> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/marcosfabricio3/simple-manager-mobile/llms.txt
> Use this file to discover all available pages before exploring further.

# RecordRepository

> Repository for managing record data persistence and retrieval operations

## Overview

The `RecordRepository` class handles all database operations for Record entities. It provides methods for creating, reading, updating, and soft-deleting records in the SQLite database.

**Location:** `src/infraestructure/repositories/RecordRepository.ts`

## Methods

### create

Creates a new record in the database.

```typescript theme={null}
async create(record: Record): Promise<void>
```

<ParamField path="record" type="Record" required>
  The record object to create

  <expandable title="Record Properties">
    <ParamField path="id" type="string" required>
      Unique identifier for the record
    </ParamField>

    <ParamField path="title" type="string" required>
      The title of the record
    </ParamField>

    <ParamField path="subtitle" type="string">
      Optional subtitle for the record
    </ParamField>

    <ParamField path="metadata" type="string">
      Optional metadata stored as string
    </ParamField>

    <ParamField path="type" type="string" required>
      The type of record
    </ParamField>

    <ParamField path="userId" type="string">
      Optional user identifier associated with the record
    </ParamField>

    <ParamField path="createdAt" type="string" required>
      Timestamp when the record was created
    </ParamField>

    <ParamField path="updatedAt" type="string" required>
      Timestamp when the record was last updated
    </ParamField>

    <ParamField path="isDeleted" type="boolean" required>
      Soft delete flag (stored as 1 or 0 in database)
    </ParamField>
  </expandable>
</ParamField>

<ResponseField name="return" type="Promise<void>">
  Resolves when the record is successfully created
</ResponseField>

**Database Interaction:**

```sql theme={null}
INSERT INTO records (
  id, title, subtitle, metadata, type, userId, createdAt, updatedAt, isDeleted
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
```

***

### findAll

Retrieves all non-deleted records from the database.

```typescript theme={null}
async findAll(): Promise<Record[]>
```

<ResponseField name="return" type="Promise<Record[]>">
  Array of all active (non-deleted) records. The `isDeleted` field is converted from numeric (0/1) to boolean.
</ResponseField>

**Database Interaction:**

```sql theme={null}
SELECT * FROM records WHERE isDeleted = 0
```

**Note:** This method automatically filters out soft-deleted records and converts the `isDeleted` field from integer to boolean.

***

### update

Updates an existing record in the database.

```typescript theme={null}
async update(record: Record): Promise<void>
```

<ParamField path="record" type="Record" required>
  The record object with updated values. The `id` field is used to identify which record to update.

  <expandable title="Updatable Fields">
    <ParamField path="title" type="string" required>
      Updated title
    </ParamField>

    <ParamField path="subtitle" type="string">
      Updated subtitle
    </ParamField>

    <ParamField path="metadata" type="string">
      Updated metadata
    </ParamField>

    <ParamField path="type" type="string" required>
      Updated type
    </ParamField>

    <ParamField path="userId" type="string">
      Updated user identifier
    </ParamField>

    <ParamField path="updatedAt" type="string" required>
      Updated timestamp
    </ParamField>
  </expandable>
</ParamField>

<ResponseField name="return" type="Promise<void>">
  Resolves when the record is successfully updated
</ResponseField>

**Database Interaction:**

```sql theme={null}
UPDATE records SET
  title = ?,
  subtitle = ?,
  metadata = ?,
  type = ?,
  userId = ?,
  updatedAt = ?
WHERE id = ?
```

**Note:** The `createdAt` and `isDeleted` fields are not updated by this method.

***

### softDelete

Marks a record as deleted without removing it from the database.

```typescript theme={null}
async softDelete(id: string): Promise<void>
```

<ParamField path="id" type="string" required>
  The unique identifier of the record to soft delete
</ParamField>

<ResponseField name="return" type="Promise<void>">
  Resolves when the record is successfully marked as deleted
</ResponseField>

**Database Interaction:**

```sql theme={null}
UPDATE records SET isDeleted = 1 WHERE id = ?
```

**Note:** Soft-deleted records are excluded from `findAll()` results but remain in the database for potential recovery or audit purposes.

***

## Usage Example

```typescript theme={null}
import { RecordRepository } from './infraestructure/repositories/RecordRepository';
import { Record } from './domain/entities/Record';

const recordRepo = new RecordRepository();

// Create a new record
const newRecord: Record = {
  id: 'rec_123',
  title: 'My Record',
  subtitle: 'A sample record',
  metadata: JSON.stringify({ key: 'value' }),
  type: 'standard',
  userId: 'user_456',
  createdAt: new Date().toISOString(),
  updatedAt: new Date().toISOString(),
  isDeleted: false
};

await recordRepo.create(newRecord);

// Get all records
const records = await recordRepo.findAll();

// Update a record
newRecord.title = 'Updated Title';
newRecord.updatedAt = new Date().toISOString();
await recordRepo.update(newRecord);

// Soft delete a record
await recordRepo.softDelete('rec_123');
```

## Database Schema

The repository interacts with the `records` table with the following structure:

| Column    | Type    | Constraints       |
| --------- | ------- | ----------------- |
| id        | TEXT    | PRIMARY KEY       |
| title     | TEXT    | NOT NULL          |
| subtitle  | TEXT    | NULLABLE          |
| metadata  | TEXT    | NULLABLE          |
| type      | TEXT    | NOT NULL          |
| userId    | TEXT    | NULLABLE          |
| createdAt | TEXT    | NOT NULL          |
| updatedAt | TEXT    | NOT NULL          |
| isDeleted | INTEGER | NOT NULL (0 or 1) |

## Related

* [Record Entity](/api/entities/record)
* [Database Configuration](/concepts/database)
