Query Types

The first and most important part of every RONIN query is its type (“query type”).

It represents the operation that is being performed at the time when the query is executed and, therefore, the way in which records are either read or written in the RONIN space that is being addressed by the query.

Creating Records (create)

To insert individual records for a given RONIN schema, the create query type can be used:

TypeScript
await create.account.with({
  name: 'Elaine Marksman',
  email: 'elaine@kojima-productions.com',
});

As usual with RONIN’s query syntax, you may choose to nest the different parts of the query in any way you like, at any level you like:

TypeScript
await create.session.with.account('acc_vais0g9rrk995tz0');

Every time you create a record, the created record is returned.

Creating multiple records at once

At the moment, inserting a list of records with a single query is not yet possible. To insert multiple records at once, you may, therefore, run a create query multiple times with different values:

TypeScript
const posts = [];
 
for (const postDetails of posts) {
  await create.post.with(postDetails);
}

Supported Query Instructions

The following query instructions may be used in combination with queries of type create:

Default Fields

Whenever a new record is created, its id field will get filled automatically. You may optionally overwrite the default value by passing the field as part of the create query.

Additionally, the ronin.createdAt and ronin.updatedAt metadata fields of the record will automatically get set to when the Record was created.

Retrieving Records (get)

To obtain all records of a given RONIN schema, the get query type can be used:

TypeScript
await get.accounts();

To obtain only specific records, you may optionally pass a list of fields that should be matched:

TypeScript
await get.account.with.id('acc_vais0g9rrk995tz0');
 
await get.accounts.with({
  handle: 'elaine',
  emailAddress: 'elaine@site.co',
});

Advanced Assertions

In most cases, the syntax above will suffice for retrieving the records you’re interested in. If it doesn’t suffice, you may optionally choose to provide more complex field assertions using the sub instructions of the with query instruction:

TypeScript
await get.accounts.with({
  email: {
    startingWith: 'team-',
    endingWith: '@site.com',
  },
});

Supported Query Instructions

The following query instructions may be used in combination with queries of type get:

  • Asserting Fields (with)

  • Paginating Records (before, after, limitedTo)

  • Ordering Records (orderedBy)

  • Resolving Related Records (including)

  • Excluding Fields (excluding)

Modifying Records (set)

To update individual records of a given RONIN schema, the set query type can be used:

TypeScript
await set.account({
  with: { id: 'acc_vais0g9rrk995tz0' },
  to: { name: 'David Marksman' },
});

Similarily, multiple records of the same RONIN schema may be updated like so:

TypeScript
await set.accounts({
  with: {
    email: {
      endingWith: 'kojima-productions.com',
    },
  },
  to: { name: 'David Marksman' },
});

Every time you update a record, the updated record (with the modifications applied) is returned.

Supported Query Instructions

The following query instructions may be used in combination with queries of type set:

  • Asserting Fields (with)

  • Resolving Related Records (including)

Default Fields

Whenever a record is modified, the ronin.updatedAt metadata field will automatically get updated to the time when the update was performed.

Deleting Records (drop)

To remove individual records of a given RONIN schema, the drop query type can be used:

TypeScript
await drop.account.with.id('acc_vais0g9rrk995tz0');

Optionally, multiple fields may be provided for matching the record that should be removed:

TypeScript
await drop.account.with({
  email: 'elaine@kojima-productions.com',
  handle: 'elaine',
});

Similarily, multiple records of the same RONIN schema may be removed like so:

TypeScript
await drop.accounts.with.email.endingWith('kojima-productions.com');

Supported Query Instructions

The following query instructions may be used in combination with queries of type drop:

  • Asserting Fields (with)

  • Resolving Related Records (including)

Deleting All Records

Please note that, for safety reasons, running drop queries without query instructions is impossible. Meaning running the query drop.accounts() is not possible.

If you would like to delete all records of a schema, please retrieve them all using a get query first and then delete them by running a drop query for every record. Alternatively, you can also delete the entire schema in the schema settings on the dashboard.

Counting Records (count)

To determine the amount of all the records available for a given RONIN schema, the count query type can be used:

TypeScript
await count.accounts();

Note that, as shown above, the count query type can only be used with the Plural Slug of a schema, not the Slug. For example, count.account() does not work, whereas count.accounts() does.

Supported Query Instructions

The following query instructions may be used in combination with queries of type count:

  • Asserting Fields (with)