Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
61 changes: 50 additions & 11 deletions docs/reference/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,64 @@ The global variables include:

## `tables`

This is an object that holds all the tables for the default database (called `data`) as properties. Each of these property values is a table class that subclasses the Resource interface and provides access to the table through the Resource interface. For example, you can get a record from a table (in the default database) called 'my-table' with:
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.

```javascript
import { tables } from 'harperdb';
const { MyTable } = tables;
async function getRecord() {
let record = await MyTable.get(recordId);
**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
}
```

It is recommended that you [define a database](../developers/applications/defining-schemas) for all the tables that are required to exist in your application. This will ensure that the tables exist on the `tables` object. Also note that the property names follow a CamelCase convention for use in JavaScript and in the GraphQL Schemas, but these are translated to snake_case for the actual table names, and converted back to CamelCase when added to the `tables` object.
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. For more info, read our complete [guide on defining schemas](../developers/applications/defining-schemas).

### Example

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

// Create a new record (`id` is automatically generated when using `.create()`)
const created = await Product.create({ name: 'Shirt', price: 9.5 });

// Modify the record
await Product.patch(created.id, { price: Math.round(created.price * 0.8 * 100) / 100 }); // 20% off!

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

logger.info('New price:', record.price);

// Query for all products with a `price` less than `8.00`
const query = {
conditions: [{ attribute: 'price', comparator: 'less_than', value: 8.0 }],
};

for await (const record of Product.search(query)) {
// ...
}
```

## `databases`

This is an object that holds all the databases in Harper, and can be used to explicitly access a table by database name. Each database will be a property on this object, each of these property values will be an object with the set of all tables in that database. The default database, `databases.data` should equal the `tables` export. For example, if you want to access the "dog" table in the "dev" database, you could do so:
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.

```javascript
import { databases } from 'harperdb';
const { Dog } = databases.dev;
### Example

```js
const Product = databases.data.Product; // 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
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. For more info, read our complete [guide on defining schemas](../developers/applications/defining-schemas).

#### Example

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

// Create a new record (`id` is automatically generated when using `.create()`)
const created = await Product.create({ name: 'Shirt', price: 9.5 });

// Modify the record
await Product.patch(created.id, { price: Math.round(created.price * 0.8 * 100) / 100 }); // 20% off!

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

logger.info('New price:', record.price);

// Query for all products with a `price` less than `8.00`
const query = {
conditions: [{ attribute: 'price', comparator: 'less_than', value: 8.0 }],
};

for await (const record of Product.search(query)) {
// ...
}
```

### `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 Product = databases.data.Product; // 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
61 changes: 50 additions & 11 deletions versioned_docs/version-4.5/reference/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,64 @@ The global variables include:

## `tables`

This is an object that holds all the tables for the default database (called `data`) as properties. Each of these property values is a table class that subclasses the Resource interface and provides access to the table through the Resource interface. For example, you can get a record from a table (in the default database) called 'my-table' with:
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.

```javascript
import { tables } from 'harperdb';
const { MyTable } = tables;
async function getRecord() {
let record = await MyTable.get(recordId);
**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
}
```

It is recommended that you [define a database](../getting-started/quickstart) for all the tables that are required to exist in your application. This will ensure that the tables exist on the `tables` object. Also note that the property names follow a CamelCase convention for use in JavaScript and in the GraphQL Schemas, but these are translated to snake_case for the actual table names, and converted back to CamelCase when added to the `tables` object.
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. For more info, read our complete [guide on defining schemas](../developers/applications/defining-schemas).

### Example

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

// Create a new record (`id` is automatically generated when using `.create()`)
const created = await Product.create({ name: 'Shirt', price: 9.5 });

// Modify the record
await Product.patch(created.id, { price: Math.round(created.price * 0.8 * 100) / 100 }); // 20% off!

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

logger.info('New price:', record.price);

// Query for all products with a `price` less than `8.00`
const query = {
conditions: [{ attribute: 'price', comparator: 'less_than', value: 8.0 }],
};

for await (const record of Product.search(query)) {
// ...
}
```

## `databases`

This is an object that holds all the databases in Harper, and can be used to explicitly access a table by database name. Each database will be a property on this object, each of these property values will be an object with the set of all tables in that database. The default database, `databases.data` should equal the `tables` export. For example, if you want to access the "dog" table in the "dev" database, you could do so:
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.

```javascript
import { databases } from 'harperdb';
const { Dog } = databases.dev;
### Example

```js
const Product = databases.data.Product; // 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
58 changes: 56 additions & 2 deletions versioned_docs/version-4.5/reference/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,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. For more info, read our complete [guide on defining schemas](../developers/applications/defining-schemas).

#### Example

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

// Create a new record (`id` is automatically generated when using `.create()`)
const created = await Product.create({ name: 'Shirt', price: 9.5 });

// Modify the record
await Product.patch(created.id, { price: Math.round(created.price * 0.8 * 100) / 100 }); // 20% off!

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

logger.info('New price:', record.price);

// Query for all products with a `price` less than `8.00`
const query = {
conditions: [{ attribute: 'price', comparator: 'less_than', value: 8.0 }],
};

for await (const record of Product.search(query)) {
// ...
}
```

### `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 Product = databases.data.Product; // 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
61 changes: 50 additions & 11 deletions versioned_docs/version-4.6/reference/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,64 @@ The global variables include:

## `tables`

This is an object that holds all the tables for the default database (called `data`) as properties. Each of these property values is a table class that subclasses the Resource interface and provides access to the table through the Resource interface. For example, you can get a record from a table (in the default database) called 'my-table' with:
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.

```javascript
import { tables } from 'harperdb';
const { MyTable } = tables;
async function getRecord() {
let record = await MyTable.get(recordId);
**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
}
```

It is recommended that you [define a database](../developers/applications/defining-schemas) for all the tables that are required to exist in your application. This will ensure that the tables exist on the `tables` object. Also note that the property names follow a CamelCase convention for use in JavaScript and in the GraphQL Schemas, but these are translated to snake_case for the actual table names, and converted back to CamelCase when added to the `tables` object.
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. For more info, read our complete [guide on defining schemas](../developers/applications/defining-schemas).

### Example

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

// Create a new record (`id` is automatically generated when using `.create()`)
const created = await Product.create({ name: 'Shirt', price: 9.5 });

// Modify the record
await Product.patch(created.id, { price: Math.round(created.price * 0.8 * 100) / 100 }); // 20% off!

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

logger.info('New price:', record.price);

// Query for all products with a `price` less than `8.00`
const query = {
conditions: [{ attribute: 'price', comparator: 'less_than', value: 8.0 }],
};

for await (const record of Product.search(query)) {
// ...
}
```

## `databases`

This is an object that holds all the databases in Harper, and can be used to explicitly access a table by database name. Each database will be a property on this object, each of these property values will be an object with the set of all tables in that database. The default database, `databases.data` should equal the `tables` export. For example, if you want to access the "dog" table in the "dev" database, you could do so:
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.

```javascript
import { databases } from 'harperdb';
const { Dog } = databases.dev;
### Example

```js
const Product = databases.data.Product; // 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
Loading