Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
84e08f5
Add usage examples for Resource class methods
baileydunning Nov 20, 2025
9ac6171
prettier
baileydunning Nov 20, 2025
bb519de
Add usage examples for global vars in versioned documentation
baileydunning Nov 20, 2025
9b1d6b7
rm usage examples
baileydunning Nov 20, 2025
f1f8ea4
Update Resource class documentation to include schema definition and …
baileydunning Nov 24, 2025
944590a
format
baileydunning Nov 24, 2025
1b433be
update
baileydunning Nov 24, 2025
e26f160
see if this fixes broken links
baileydunning Nov 24, 2025
ad096c7
format
baileydunning Nov 24, 2025
15e3751
update globals page with new examples
baileydunning Nov 24, 2025
97b1429
apply comments
baileydunning Nov 24, 2025
15b95e7
try this
baileydunning Nov 24, 2025
704270e
Update docs/reference/globals.md
baileydunning Nov 24, 2025
1d9d294
Update docs/reference/globals.md
baileydunning Nov 24, 2025
e1a569a
Update docs/reference/globals.md
baileydunning Nov 24, 2025
5e497b3
Update docs/reference/resources/index.md
baileydunning Nov 24, 2025
8a6a8e0
Update docs/reference/resources/index.md
baileydunning Nov 24, 2025
ad9ad51
Update docs/reference/resources/index.md
baileydunning Nov 24, 2025
682d7a7
apply ethan updates
baileydunning Nov 24, 2025
4ebd3ff
format
baileydunning Nov 24, 2025
ec62174
make it just Product instead of ProductTable
baileydunning Nov 25, 2025
3489c76
update example
baileydunning Nov 25, 2025
2f49eeb
update put example
baileydunning Nov 25, 2025
451d262
update again!
baileydunning Nov 25, 2025
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
58 changes: 56 additions & 2 deletions docs/reference/resources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,65 @@ All Resource methods that are called from HTTP methods may directly return data

### `tables`

This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created will be available as a (standard) property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to add this, I wonder if it should be at line 58 before we first reference tables.MyTable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized we have two "Globals" references in the docs. The top-level page and then this subsection. TBH i don't think we need to tackle reorganization within this pr. Just updating the sections in place with more details is helpful enough and then we'll make larger organization and flow changes later.

This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created in your `schema.graphql` file will be available as a property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.

**Schema Definition:**
Tables are defined in your `schema.graphql` file using the `@table` directive. For example:

```graphql
type Product @table {
id: ID @primaryKey
name: String
price: Float
}
```

Once declared, `Product` will be available as `tables.Product` (or `databases.data.Product`). This mapping is automatic: every table defined in the default database in your schema will appear as a property on the `tables` object.

#### Example

```js
const MyTable = tables.table_name; // Same as databases.data.MyTable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tables === databases.data, but table_name !== MyTable !== Product. Throughout this, I am not sure if we are trying to stick to Product, MyTable, or table_name.


// Within your Resource class:
// Create a new record (ID generated)
const created = await MyTable.create({ name: 'Example', status: 'active' });

// Retrieve by primary key
const record = await MyTable.get(created[MyTable.id]);

// Insert or replace by ID
await MyTable.put(created[MyTable.id], { ...record, status: 'inactive' });

// Run a query
const query = {
conditions: [{ attribute: 'status', value: 'active' }],
limit: 50,
};

for await (const record of MyTable.search(query)) {
// Handle each row
}
```

### `databases`

This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created will be available as a (standard) property on this object. The property values are an object with the tables in that database, where each property is a table, like the `tables` object. In fact, `databases.data === tables` should always be true.
This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created in your `schema.graphql` file will be available as a property on this object. The property values are objects containing the tables in that database, where each property is a table, just like the `tables` object. In fact, `databases.data === tables` should always be true.

#### Example

```js
const MyTable = databases.data.MyTable; // Default database
const Events = databases.analytics.Events; // Another database

// Create a new event record
const event = await Events.create({ eventType: 'login', timestamp: Date.now() });

// Query events
for await (const e of Events.search({ conditions: [{ attribute: 'eventType', value: 'login' }] })) {
// Handle each event
}
```

### `Resource`

Expand Down
32 changes: 32 additions & 0 deletions versioned_docs/version-4.5/reference/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,42 @@ All Resource methods that are called from HTTP methods may directly return data

This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created will be available as a (standard) property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.

#### Example

```js
const MyTable = tables.table_name;

// Within your Resource class:
// Create a new record (ID generated)
const created = await MyTable.create({ name: 'Example', status: 'active' });

// Retrieve by primary key
const record = await MyTable.get(created[MyTable.id]);

// Insert or replace by ID
await MyTable.put(created[MyTable.id], { ...record, status: 'inactive' });

// Run a query
const query = {
conditions: [{ attribute: 'status', value: 'active' }],
limit: 50,
};

for await (const record of MyTable.search(query)) {
// Handle each row
}
```

### `databases`

This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created will be available as a (standard) property on this object. The property values are an object with the tables in that database, where each property is a table, like the `tables` object. In fact, `databases.data === tables` should always be true.

#### Example

```js
const MyTable = databases.data.table_name;
```

### `Resource`

This is the Resource base class. This can be directly extended for custom resources, and is the base class for all tables.
Expand Down
60 changes: 57 additions & 3 deletions versioned_docs/version-4.6/reference/resources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,65 @@ All Resource methods that are called from HTTP methods may directly return data

### `tables`

This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created will be available as a (standard) property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.
This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created in your `schema.graphql` file will be available as a property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.

**Schema Definition:**
Tables are defined in your `schema.graphql` file using the `@table` directive. For example:

```graphql
type Product @table {
id: ID @primaryKey
name: String
price: Float
}
```

Once declared, `Product` will be available as `tables.Product` (or `databases.data.Product`). This mapping is automatic: every table defined in the default database in your schema will appear as a property on the `tables` object.

#### Example

```js
const MyTable = tables.table_name; // Same as databases.data.MyTable

// Within your Resource class:
// Create a new record (ID generated)
const created = await MyTable.create({ name: 'Example', status: 'active' });

// Retrieve by primary key
const record = await MyTable.get(created[MyTable.id]);

// Insert or replace by ID
await MyTable.put(created[MyTable.id], { ...record, status: 'inactive' });

// Run a query
const query = {
conditions: [{ attribute: 'status', value: 'active' }],
limit: 50,
};

for await (const record of MyTable.search(query)) {
// Handle each row
}
```

### `databases`

This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created will be available as a (standard) property on this object. The property values are an object with the tables in that database, where each property is a table, like the `tables` object. In fact, `databases.data === tables` should always be true.
This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created in your `schema.graphql` file will be available as a property on this object. The property values are objects containing the tables in that database, where each property is a table, just like the `tables` object. In fact, `databases.data === tables` should always be true.

#### Example

```js
const MyTable = databases.data.MyTable; // Default database
const Events = databases.analytics.Events; // Another database

// Create a new event record
const event = await Events.create({ eventType: 'login', timestamp: Date.now() });

// Query events
for await (const e of Events.search({ conditions: [{ attribute: 'eventType', value: 'login' }] })) {
// Handle each event
}
```

### `Resource`

Expand All @@ -102,7 +156,7 @@ This object provides extension points for extension components that wish to impl

### `transaction`

This provides a function for starting transactions. See the transactions section below for more information.
This provides a function for starting transactions. See the [transactions documentation](./transactions) for more information.

### `contentTypes`

Expand Down
58 changes: 56 additions & 2 deletions versioned_docs/version-4.7/reference/resources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,65 @@ All Resource methods that are called from HTTP methods may directly return data

### `tables`

This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created will be available as a (standard) property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.
This is an object with all the tables in the default database (the default database is "data"). Each table that has been declared or created in your `schema.graphql` file will be available as a property on this object, and the value will be the table class that can be used to interact with that table. The table classes implement the Resource API.

**Schema Definition:**
Tables are defined in your `schema.graphql` file using the `@table` directive. For example:

```graphql
type Product @table {
id: ID @primaryKey
name: String
price: Float
}
```

Once declared, `Product` will be available as `tables.Product` (or `databases.data.Product`). This mapping is automatic: every table defined in the default database in your schema will appear as a property on the `tables` object.

#### Example

```js
const MyTable = tables.table_name; // Same as databases.data.MyTable

// Within your Resource class:
// Create a new record (ID generated)
const created = await MyTable.create({ name: 'Example', status: 'active' });

// Retrieve by primary key
const record = await MyTable.get(created[MyTable.id]);

// Insert or replace by ID
await MyTable.put(created[MyTable.id], { ...record, status: 'inactive' });

// Run a query
const query = {
conditions: [{ attribute: 'status', value: 'active' }],
limit: 50,
};

for await (const record of MyTable.search(query)) {
// Handle each row
}
```

### `databases`

This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created will be available as a (standard) property on this object. The property values are an object with the tables in that database, where each property is a table, like the `tables` object. In fact, `databases.data === tables` should always be true.
This is an object with all the databases that have been defined in Harper (in the running instance). Each database that has been declared or created in your `schema.graphql` file will be available as a property on this object. The property values are objects containing the tables in that database, where each property is a table, just like the `tables` object. In fact, `databases.data === tables` should always be true.

#### Example

```js
const MyTable = databases.data.MyTable; // Default database
const Events = databases.analytics.Events; // Another database

// Create a new event record
const event = await Events.create({ eventType: 'login', timestamp: Date.now() });

// Query events
for await (const e of Events.search({ conditions: [{ attribute: 'eventType', value: 'login' }] })) {
// Handle each event
}
```

### `Resource`

Expand Down