Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions skills/base44-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,27 @@ Run one-off scripts against your app with the Base44 SDK pre-authenticated. Use

**SPA only**: Base44 hosting supports Single Page Applications with a single `index.html` entry point. All routes are served from `index.html` (client-side routing).

### Logs

| Command | Description |
|---------|-------------|
| `base44 logs [options]` | View function execution logs |

**Flags:**
- `--function <name>` — Filter by function name (comma-separated for multiple)
- `--level <info|warning|error|debug>` — Filter by log level
- `--since <ISO-datetime>` — Show logs after this time
- `--until <ISO-datetime>` — Show logs before this time
- `--limit <N>` — Results per page (1-1000)
- `--order <asc|desc>` — Sort order (default: desc)

**Example:**
```bash
npx base44 logs --function my-function --level error --since 2024-03-01T00:00:00Z
```

For detailed logs documentation, see the base44-troubleshooter skill.

## Quick Start

1. Install the CLI in your project:
Expand Down
48 changes: 48 additions & 0 deletions skills/base44-sdk/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,54 @@ const base44 = createClient({
- Track custom events → `analytics.track()`
- Log page views/activity → `appLogs.logUserInApp()`

## Backend Function Best Practices

### Avoid scanning large collections

Backend functions run in Deno with limited memory. Fetching large entity collections with `list()` may fail for collections with thousands of records.

**Instead of scan-and-aggregate:**
```javascript
// ❌ Fragile — fails as collection grows
const allUsages = await base44.entities.Usage.list("-created_date", 5000);
const counts = {};
for (const u of allUsages) { counts[u.user_id] = (counts[u.user_id] || 0) + 1; }
```

**Use incremental pre-computed stats:**
```javascript
// ✅ Update a stats record on each new event (via entity hook automation)
const stats = await base44.entities.UserStats.filter({ user_id: userId }, null, 1);
if (stats.length > 0) {
await base44.entities.UserStats.update(stats[0].id, { total: stats[0].total + 1 });
}
```

### Use filter() with specific conditions

`filter()` with targeted conditions returns smaller result sets and works reliably:
```javascript
// ✅ Small, targeted query
const userStats = await base44.entities.UserStats.filter({ user_id: "U123" }, null, 1);
```

### Use pagination for large reads

When you need to process many records, paginate with `skip`:
```javascript
let skip = 0;
while (true) {
const batch = await base44.entities.Task.list("-created_date", 100, skip);
if (batch.length === 0) break;
// process batch
skip += 100;
}
```

### Use the REST API for data migrations

For one-time backfills or large data operations, use the Base44 REST API (`https://app.base44.com/api/apps/{appId}/entities/{EntityName}`) from a local script instead of a backend function.

## Common Patterns

### Filter and Sort Data
Expand Down
2 changes: 1 addition & 1 deletion skills/base44-troubleshooter/references/project-logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npx base44 logs [options]
| `--function <names>` | Filter by function name(s), comma-separated. If omitted, fetches logs for all project functions | No |
| `--since <datetime>` | Show logs from this time (ISO format) | No |
| `--until <datetime>` | Show logs until this time (ISO format) | No |
| `--level <level>` | Filter by log level: `log`, `info`, `warn`, `error`, `debug` | No |
| `--level <level>` | Filter by log level: `info`, `warning`, `error`, `debug` | No |
| `-n, --limit <n>` | Number of results to return (1-1000, default: 50) | No |
| `--order <order>` | Sort order: `asc` or `desc` (default: `desc`) | No |

Expand Down
Loading