Skip to content

09 TypeDB Loader as Dependency

Joshua Send edited this page Mar 15, 2024 · 2 revisions

Maven:

Add jitpack and grakn as repositories:

<repositories>
    <repository>
        <id>typedb</id>
        <url>https://repo.typedb.com/public/public-release/maven</url>
    </repository>
    <repository>
        <id>typedb-osi</id>
        <url>https://repo.typedb.com/public/osi/maven/</url>
    </repository>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Add TypeDB Loader as dependency:

<dependency>
    <groupId>com.vaticle.typedb-osi</groupId>
    <artifactId>typedb-loader</artifactId>
    <version>__VERSION__</version>
</dependency>

Gradle:

Add jitpack and typedb as repositories:

repositories {
    ...
    maven { url 'https://repo.typedb.com/public/public-release/maven/'}
    maven { url 'https://repo.typedb.com/public/osi/maven/'}
    maven { url 'https://jitpack.io' }
}

Add GraMi as dependency:

dependencies {
    ...
    implementation 'com.vaticle.typedb-osi:typedb-loader:1.2.0'
}

Example Migration Class

In your favorite IDE, create a Class that will handle your migration (here: migration.Migration):

public class LoadingData {

    public void loadData() {
        String uri = "localhost:1729";
        String config = "path/to/your/config.json";
        String database = "databaseName";

        String[] args = {
                "load",
                "-tdb", uri,
                "-c", config,
                "-db", database,
                "-cm"
        };

        LoadOptions options = LoadOptions.parse(args);
        TypeDBLoader loader = new TypeDBLoader(options);
        loader.load();
    }
}

The "-cm" flag stands for "clean and migrate", which will delete the database, its schema and data, if exists, reapply the provided schema, and load the data according to the configuration.