00:00:16.320
Okay, so hello everyone. Good morning.
00:00:22.080
Thank you for coming to my session on the last day in the morning; I really appreciate it.
00:00:28.480
Today, I'm going to talk about Datomic from Ruby on Rails. It's a straightforward title, and I'm excited to share my insights.
00:00:36.320
My name is Yoko Harada, and you can find me on GitHub and Twitter under the username 'yokuharada'.
00:00:44.800
I'm a JRuby core contributor and a JRuby enthusiast, which is quite important to remember.
00:00:52.160
I'm also a contributor to the NoCalgary project, and I work for Pure Java at NoCalgary.
00:01:03.680
As a Japanese person, I find some words a bit difficult to pronounce, including 'relevance'.
00:01:10.720
Currently, I work for Relevance as a developer. Today, I will cover three main topics.
00:01:28.560
First, I will introduce the Diametric gem. Then, I'll provide an overview of Datomic for those who are unfamiliar with it.
00:01:34.640
Finally, I'll delve into the details of how the Diametric gem works.
00:01:40.720
To start, the Diametric gem is an ActiveModel wrapper for Datomic.
00:01:46.399
Using this gem, developers can interact with Datomic in a way that's familiar to Rubyists.
00:01:53.520
For those who do not know, Datomic is a database that leverages immutable data.
00:02:00.159
It's built on a different paradigm than traditional relational databases.
00:02:05.360
The first thing I need to clarify is that the Diametric gem is hosted by Relevance.
00:02:10.000
However, it is an open-source project, allowing anyone to contribute. I appreciate any pull requests from the community.
00:02:26.080
Relevance sells Datomic licenses and provides consulting, but the gem itself is a third-party product.
00:02:33.599
Now, I'd like to discuss something called coding time.
00:02:40.800
Our employees are encouraged to work on projects of their choice during what we call '20% time,' which occurs every Friday.
00:02:55.440
During last year's JRubyConf, I worked on a picture project as part of this initiative.
00:03:09.760
Three developers have significantly contributed to the Diametric gem.
00:03:15.120
Quentin introduced the project, followed by Ryan, and I joined later.
00:03:22.320
At present, I am the only one actively contributing to the gem.
00:03:27.440
The Diametric gem presents certain challenges. I will show examples of how Datomic functions later.
00:03:35.280
When people mention Datomic, it often comes with the association of Clojure, which is the language primarily used with it.
00:03:48.480
Many developers prefer to use Datomic with Clojure, but there is also a Java API available that can be accessed via REST services.
00:03:55.680
For Rubyists, we will need to make some adjustments, which I will discuss further.
00:04:05.440
Now, let's talk about Datomic itself.
00:04:10.800
Datomic was created by Rich Hickey, the well-known creator of Clojure.
00:04:27.040
There are often questions about whether Rich Hickey works for Relevance; the answer is no.
00:04:32.479
Datomic is a joint venture between Rich and Relevance, and they collaborate on its development.
00:04:44.000
Now, let's discuss the definitions related to Datomic and its categorization.
00:04:57.679
It is classified as a NewSQL database, but naming conventions can be confusing.
00:05:08.160
Datomic guarantees ACID properties akin to those found in traditional RDBMS.
00:05:14.720
Rich Hickey designed Datomic with simplicity in mind, ensuring minimal schema and data structures.
00:05:21.359
In Datomic, the schema is represented as simple arrays and hashes.
00:05:36.640
Here's an example: don't worry too much about the schema itself.
00:05:44.800
Clojure developers can define the schema, but the Diametric gem generates an appropriate schema for Ruby.
00:05:58.480
A few key features distinguish Datomic from traditional RDBMS.
00:06:12.680
First, in Datomic, data is treated as immutable.
00:06:27.679
This architecture allows for reasoning over time effectively.
00:06:39.039
For instance, if we have a table with a boyfriend's picture, when a new picture is added, the old one is not deleted; instead, a fact is created.
00:06:54.480
This approach removes the need for data deletion, as Datomic implements this with a focus on immutability.
00:07:11.760
Rich Hickey called this approach 'fact-oriented programming,' wherein facts are never altered.
00:07:26.880
A good example of this is how GitHub IDs remain as facts that can be traversed over time.
00:07:39.120
The ability to roll back to previous states is a significant advantage in Datomic.
00:07:47.360
Let's consider a database state rollback example, representing a point in time.
00:07:55.680
In essence, we can visualize this feature as an OS X time machine.
00:08:07.920
On the programming side, Datomic has a Closure and Java API, along with its query engine.
00:08:24.719
This structure makes Datomic highly scalable because we can control operations from the programming level.
00:08:37.360
To summarize, Datomic distinguishes itself from traditional RDBMS through its handling of facts and immutability.
00:08:51.760
Let's shift our focus back to the Diametric gem.
00:09:02.880
The gem simplifies how we interact with Datomic, as we do not need to manually handle the schema.
00:09:12.560
In the gem, we define classes that include the Diametric entity, and it manages the schema for us.
00:09:20.320
Thus, integrating peer services into our Ruby applications is straightforward.
00:09:28.640
Using the API, we can set attributes and interact with the data seamlessly.
00:09:42.480
The Diametric gem generates dynamic transaction data to simplify data operations.
00:09:56.560
When we create a new model instance and save it, all the transactions are managed effectively.
00:10:06.720
In the case of updating or deleting records, the gem handles this with the concept of transactions as well.
00:10:18.560
Next, I’ll provide a brief demonstration of working with the Diametric gem.
00:10:30.480
First, I’ll connect to Datomic and create a schema.
00:10:41.680
The Diametric gem generates the required schema for our application, allowing us to proceed without complications.
00:10:56.240
The ability to specify connections and define attributes is incredibly useful.
00:11:11.360
When querying, we can leverage the gem to simplify interaction with the data.
00:11:26.720
For instance, the gem provides an easy way to filter results based on specific attributes.
00:11:44.560
Furthermore, the framework supports complex queries, making it manageable to retrieve relevant entries.
00:12:01.680
Let's talk about a more complicated example involving neighborhoods.
00:12:16.640
In this instance, the challenge is navigating relationships between different data models.
00:12:29.440
For example, I’m looking to identify neighborhoods based on certain characteristics, which can be straightforward with the right queries.
00:12:45.440
The data structure allows for easy traversal up and down the relationships.
00:12:56.480
This flexibility is one of the strengths of using Datomic with the Diametric gem.
00:13:08.160
As such, querying for complex nested data or relationships becomes feasible.
00:13:24.320
The capability to read all current data states, even with large datasets, further emphasizes Datomic's efficiency.
00:13:37.360
We often deal with many results, and this performance is crucial for applications that rely on rapid data access.
00:13:55.920
By defining schemas carefully, we can ensure seamless integration into Ruby applications.
00:14:06.799
Returning to the original context, let’s consider the practical implementation of Datomic from Rails.
00:14:23.880
This setup allows Ruby developers to interact with Datomic as they would with standard database systems.
00:14:36.240
I have a working example of integrating Datomic, showcasing its functionality with Rails.
00:14:53.200
In this project, I utilized jRuby on Rails and the Diametric gem.
00:14:59.360
This integration serves as a valuable demonstration of how these technologies can cooperate.
00:15:06.000
The outcome is a functional Rails application leveraging the strengths of Datomic.
00:15:17.680
To conclude, while there are some challenges with mapping functions, the overall experience has been rewarding.
00:15:31.840
I encourage contributions from the community to improve the gem further.
00:15:53.680
Thank you all for attending this session, and I hope you can explore the possibilities that Datomic and the Diametric gem offer Ruby developers.
00:16:15.680
If you have any questions or need clarification on anything discussed, feel free to ask.