Skip to content
Open
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
2 changes: 1 addition & 1 deletion release-notes/v4-tucker/4.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ An important change is that logging to standard out/error will _not_ include the

### Data Loader

4.6 includes a new [data loader](/docs/developers/applications/data-loader) that can be used to load data into HarperDB as part of a component. The data loader can be used to load data from JSON file and can be deployed and distributed with a component to provide a reliable mechanism for ensuring specific records are loaded into Harper.
4.6 includes a new [data loader](/docs/reference/applications/data-loader) that can be used to load data into HarperDB as part of a component. The data loader can be used to load data from JSON file and can be deployed and distributed with a component to provide a reliable mechanism for ensuring specific records are loaded into Harper.

### Resource API Upgrades

Expand Down
181 changes: 0 additions & 181 deletions versioned_docs/version-4.6/developers/applications/data-loader.md

This file was deleted.

134 changes: 134 additions & 0 deletions versioned_docs/version-4.6/developers/applications/loading-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
title: Loading Data
---

# Loading Data

Now that you’ve set up your first application, let’s bring it to life with some data. Applications are only as useful as the information they hold, and Harper makes it simple to seed your database with initial records, configuration values, or even test users, without needing to write a custom script. This is where the Data Loader plugin comes in.

Think of the Data Loader as your shortcut for putting essential data in place from day one. Whether it’s a set of default settings, an admin user account, or sample data for development, the Data Loader ensures that when your application is deployed, it’s immediately usable.

In this section, we’ll add a few dogs to our `Dog` table so our application starts with meaningful data.

## Creating a Data File

First, let’s make a `data` directory in our app and create a file called `dogs.json`:

```json
{
"database": "myapp",
"table": "Dog",
"records": [
{
"id": 1,
"name": "Harper",
"breed": "Labrador",
"age": 3,
"tricks": ["sit"]
},
{
"id": 2,
"name": "Balto",
"breed": "Husky",
"age": 5,
"tricks": ["run", "pull sled"]
}
]
}
```

This file tells Harper: _“Insert these two records into the `Dog` table when this app runs.”_

## Connecting the Data Loader

Next, let’s tell Harper to use this file when running the application. Open `config.yaml` in the root of your project and add:

```yaml
dataLoader:
files: 'data/dogs.json'
```

That’s it. Now the Data Loader knows where to look.

## Running with Data

Go ahead and start your app again:

```bash
harperdb dev .
```

This time, when Harper runs, it will automatically read `dogs.json` and load the records into the Dog table. You don’t need to write any import scripts or SQL statements, it just works.

You can confirm the data is there by hitting the endpoint you created earlier:

```bash
curl http://localhost:9926/Dog/
```

You should see both `Harper` and `Balto` returned as JSON.

:::info
💡 Notice the trailing `/` in the URL (`/Dog/`). This tells Harper to return all records in the table. Leaving it off would look for a single record instead.

For more details on querying tables, resources, and records with the REST plugin, see the [REST reference docs](../../developers/rest).
:::

### Updating Records

What happens if you change the data file? Let’s update Harper’s age from 3 to 4 in `dogs.json.`

```json
{
"id": 1,
"name": "Harper",
"breed": "Labrador",
"age": 4,
"tricks": ["sit"]
}
```

When you save the file, Harper will notice the change and reload. The next time you query the endpoint, Harper’s age will be updated.

The Data Loader is designed to be safe and repeatable. If a record already exists, it will only update when the file is newer than the record. This means you can re-run deployments without worrying about duplicates.

### Adding More Tables

If your app grows and you want to seed more than just dogs, you can create additional files. For example, a `breeds.yaml` file:

```yaml
database: myapp
table: Breed
records:
- id: 1
name: Labrador
size: Large
lifespan: 12
- id: 2
name: Husky
size: Medium
lifespan: 14
```

Then add it to your config:

```yaml
dataLoader:
files:
- 'data/dogs.json'
- 'data/breeds.yaml'
```

Harper will read both files and load them into their respective tables.

## Key Takeaway

With the Data Loader, your app doesn’t start empty. It starts ready to use. You define your schema, write a simple data file, and Harper takes care of loading it. This keeps your applications consistent across environments, safe to redeploy, and quick to get started with.

In just a few steps, we’ve gone from an empty Dog table to a real application with data that’s instantly queryable.

## Related Documentation

- [Data Loader Reference](../../reference/applications/data-loader) – Complete configuration and format options.
- [Bulk Operations](../operations-api/bulk-operations) - For loading data via the Operations API
- [Plugins](../../reference/components/plugins) – For adding custom functionality to applications.
Loading