<commit_before>= Monarch

Monarch is a relational modeling framework for client-heavy web applications.
It's similar to Backbone.js, but based on the powerful abstractions of
relational algebra, offering a declarative and compositional language for
querying data and subscribing to events.


== Defining Models

Monarch associates model constructors with tables in an in-memory relational
database, similar to how ActiveRecord associates a Ruby class with a table in
MySQL.

```js
Blog = Monarch('Blog', {
  userId: 'integer',
  title: 'string',
  createdAt: 'datetime'
});

BlogPost = Monarch('BlogPost', {
  blogId: 'integer',
  title: 'string',
  body: 'string',
});
```

To define a constructor/table pair, call the global `Monarch` function
with the constructor's name (for debugging purposes) and a hash of column
declarations. The columns hash contains each column's name as a key and each
column's type as a value. Every table is given an integer-typed `id` column as
its primary key by default. This will return a constructor function that you can
assign to a global variable.

== Loading Data

Once you've defined some tables, you can load data into the client-side database
by calling `Monarch.Repository.update` with a hash of records.

```js
Monarch.Repository.update({
  blogs: {
    1: { user_id: 1, title: "Blog I Never Update", created_at: 1332433460811 },
    2: { user_id: 2, title: "Blog That No One Reads", created_at: 1332433434561 }
  }
  blog_posts: {
    1: { blog_id: 1, title: "First Post", body: "More to come!" },
    2: { blog_id: 2, title: "I'm Lonely'", body: "Please read my LiveJournal." },
    3: { blog_id: 2, title: "Comments", body: "No one commented on my last post." }
  }
});
```

As you can see above, the hash can contain records for multiple tables, and is
structured as follows: `table_name -> record_id-> column_name -> field_value.`
Note that the keys are in underscore format rather than camel case. If a record
for a given (table name, id) pair already exists, it will be updated with the
new values. Otherwise a new record will be created.

You can also call `Monarch.Repository.update` with an array of CRUD operations.
This is useful, for example, when you are handling update events delivered via a
web socket.

```js
Monarch.Repository.update([
  ['create', 'blog_posts', { id: 3, blog_id: 2, title: "I Love Star Wars!" }],
  ['update', 'blog_posts', 2, { title: "I Can't Decide on a Title'" }],
  ['destroy', 'blog_posts', 2]
])
```

== Working with Records

<commit_msg>Fix language name on code blocks<commit_after>= Monarch

Monarch is a relational modeling framework for client-heavy web applications.
It's similar to Backbone.js, but based on the powerful abstractions of
relational algebra, offering a declarative and compositional language for
querying data and subscribing to events.


== Defining Models

Monarch associates model constructors with tables in an in-memory relational
database, similar to how ActiveRecord associates a Ruby class with a table in
MySQL.

```javascript
Blog = Monarch('Blog', {
  userId: 'integer',
  title: 'string',
  createdAt: 'datetime'
});

BlogPost = Monarch('BlogPost', {
  blogId: 'integer',
  title: 'string',
  body: 'string',
});
```

To define a constructor/table pair, call the global `Monarch` function
with the constructor's name (for debugging purposes) and a hash of column
declarations. The columns hash contains each column's name as a key and each
column's type as a value. Every table is given an integer-typed `id` column as
its primary key by default. This will return a constructor function that you can
assign to a global variable.

== Loading Data

Once you've defined some tables, you can load data into the client-side database
by calling `Monarch.Repository.update` with a hash of records.

```javascript
Monarch.Repository.update({
  blogs: {
    1: { user_id: 1, title: "Blog I Never Update", created_at: 1332433460811 },
    2: { user_id: 2, title: "Blog That No One Reads", created_at: 1332433434561 }
  }
  blog_posts: {
    1: { blog_id: 1, title: "First Post", body: "More to come!" },
    2: { blog_id: 2, title: "I'm Lonely'", body: "Please read my LiveJournal." },
    3: { blog_id: 2, title: "Comments", body: "No one commented on my last post." }
  }
});
```

As you can see above, the hash can contain records for multiple tables, and is
structured as follows: `table_name -> record_id-> column_name -> field_value.`
Note that the keys are in underscore format rather than camel case. If a record
for a given (table name, id) pair already exists, it will be updated with the
new values. Otherwise a new record will be created.

You can also call `Monarch.Repository.update` with an array of CRUD operations.
This is useful, for example, when you are handling update events delivered via a
web socket.

```javascript
Monarch.Repository.update([
  ['create', 'blog_posts', { id: 3, blog_id: 2, title: "I Love Star Wars!" }],
  ['update', 'blog_posts', 2, { title: "I Can't Decide on a Title'" }],
  ['destroy', 'blog_posts', 2]
])
```

== Working with Records


{'fraction_non_alphanumeric': 0.10088321884200196, 'fraction_numerical': 0.015701668302257114, 'mean_word_length': 4.319415448851775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3565182', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1466, 'n_words': 701}