I’ve been working for a while on an ODM called Soukai.
The idea of using this library is that it has a common interface to define data models, and using different engines it can interact with different data sources. This is similar to existing Active Record implementations. One of such engine is soukai-solid, which allows to store models in Solid PODs.
I know what some think about Active Record, and the eternal discussion if it’s correct using it vs Data Mappers. But I won’t go into that, suffice to say that this is an opinionated library and you don’t have to use it if you don’t like it. I just want to share my work so that it can help others :).
On that note, I think LDflex is already a great tool to work with Solid using the Data Mapper paradigm. Although I can’t say for sure because I haven’t used it extensively, my apologies if it isn’t a fair comparison.
Example
So, how does this work? Here’s the classical example of interacting with a foaf:Person
document.
First you’d define the Person model:
import { FieldType } from 'soukai';
import { SolidModel } from 'soukai-solid';
class Person extends SolidModel {
static rdfContexts = {
'foaf': 'http://cmlns.com/foaf/0.1/',
};
static rdfsClasses = ['foaf:Person'];
static fields = {
name: FieldType.String,
friendUrls: {
type: FieldType.Array,
rdfProperty: 'foaf:knows',
items: { type: FieldType.Key },
},
};
}
And after setting up the engine, you can use it as such:
const alice = await Person.find('https://example.com/alice/card#me');
alert(`Hello, ${alice.name}!`);
// You should see something such as {"name": "Alice", "friendUrls": [...]} in the console
console.log(alice.getAttributes());
// Add a new friend
await alice.update({
friendUrls: [
...alice.friendUrls,
'https://example.com/john/card#me',
],
});
This is of course a very simple example, if you are interested in learning more I suggest that you read the documentation of both soukai and soukai-solid.
Current Status
I’ve used the library on a task manager I’m developing for Solid, Solid Focus. You can look at the source code of that project to learn how this is used in a real-world application.
This is still one of the very first versions of the library, but I’ve tried to write a thorough documentation of the current features. I’m eager to hear your opinions and get some feedback.