TypeDB: A Polymorphic Database with Strong Typing and Reasoning Capabilities
TypeDB is a cutting-edge database technology that aims to revolutionize the way we interact with data. Unlike traditional relational and NoSQL databases, TypeDB introduces a strong type system, extending it with inference and pattern matching capabilities for more powerful querying[^1^]. This article aims to provide an in-depth look at TypeDB, its features, and why it could be a game-changer in the database landscape.
One more FOOS project with a open code github
Why TypeDB?
The primary motivation behind TypeDB is to bring the benefits of strong typing to databases. In software development, strong typing helps in catching errors early, improving code readability, and making the system more maintainable. TypeDB believes that these advantages should extend to databases as well[^1^].
Core Features
- Polymorphic Database: TypeDB is not just another database; it’s a polymorphic database. This means it can adapt to various data models and structures, providing a more flexible approach to data storage[^2^].
match $user isa user,
has full-name $name,
has email $email;
# This returns all users of any type
match $user isa employee,
has full-name $name,
has email $email,
has employee-id $id;
# This returns only users who are employees
match $user-type sub user;
$user isa $user-type,
has full-name $name,
has email $email;
# This returns all users and their type
- Conceptual Data Model: At its core, TypeDB uses a conceptual data model. This allows for a more intuitive understanding of the data, making it easier for developers and data scientists to work with the database[^2^].
insert
$john isa full-time-employee,
has full-name "John Doe",
has primary-email "john.doe@vaticle.com",
has email "j.doe@vaticle.com",
has email "john@vaticle.com",
has employee-id 183;
$readme isa file, has path "/usr/johndoe/repos/typedb/readme.md";
$edit isa action, has name "edit file";
$kevin isa user, has email "kevin@vaticle.com";
$perm (subject: $john, object: $readme, action: $edit) isa permission;
$rqst (target: $perm, requestee: $kevin) isa change-request, has requested-change "revoke";
- Strong Subtyping System: One of the standout features is its strong subtyping system. This ensures that the data conforms to predefined types, thereby reducing errors and improving data integrity[^2^].
define
rule transitive-team-membership: when {
(team: $team-1, member: $team-2) isa team-membership;
(team: $team-2, member: $member) isa team-membership;
} then { (team: $team-1, member: $member) isa team-membership; };
insert
$john isa user, has email "john@vaticle.com";
$eng isa team, has name "Engineering ";
$cloud isa team, has name "Cloud";
(team: $eng, member: $cloud) isa team-membership;
(team: $cloud, member: $john) isa team-membership;
match
$john isa user, has email "john@vaticle.com";
(team: $team, member: $john) isa team-membership;
# This will return both Cloud and Engineering for $team due to the defined rule
- Symbolic Reasoning Engine: TypeDB comes with a built-in reasoning engine that can perform symbolic reasoning. This is particularly useful for complex queries where logical inference is required[^2^].
define
full-name sub attribute, value string;
id sub attribute, value string;
email sub id;
employee-id sub id;
user sub entity,
owns full-name,
owns email @unique;
employee sub user,
owns employee-id @key,
plays team-membership:member;
membership sub relation, abstract,
relates parent,
relates member;
team-membership sub membership,
relates team as parent;
- TypeQL: TypeDB uses its own query language called TypeQL. It’s a type-theoretic language that is both beautiful and elegant, designed to make querying as simple and powerful as possible[^2^].
- Pattern Matching TypeQL works through declarative pattern matching, allowing queries to be scoped to any level in the type hierarchy without considering physical data stores or execution strategy.
match
$user isa user;
match
$user isa user, has email "john@vaticle.com";
match
$user isa user, has email "john@vaticle.com";
(subject: $user, object: $tql, action: $action) isa permission;
$tql isa file, has extension "tql";
match
$user isa user;
(subject: $user, object: $tql, action: $action) isa permission;
$tql isa file, has extension "tql";
(team: $eng, member: $user) isa team-membership;
$eng isa team, has name "Engineering";
Development and Schema
TypeDB offers essential information on types, inheritance, queries, pattern matching, and inference through its documentation portal[^3^]. It also provides guidelines on connecting to the TypeDB server, defining the database schema, and other development-related tasks[^3^].
Applications and Solutions
TypeDB finds its applications in various domains like Intelligent Infrastructure, Cybersecurity, IAM (Identity and Access Management), CTI (Cyber Threat Intelligence), ASM (Application Security Management), and TDR (Threat Detection and Response)[^4^]. It also has solutions for Platform Engineering, including IDP (Identity Provider), CI/CD (Continuous Integration/Continuous Deployment), Developer Portal, and Control Plane[^4^].
Conclusion
TypeDB is more than just a database; it’s a step towards making databases intelligent, type-safe, and capable of reasoning. With its strong typing system, conceptual data model, and powerful query language, TypeDB is poised to redefine the database landscape.
References
[^1^]: TypeDB Introduction [^2^]: TypeDB Home [^3^]: TypeDB Documentation Overview [^4^]: TypeDB Solutions

Write a comment