csv_to_tql_insert_script
Automatically generates a TypeQL script for doing entity and relationship insertions from a .csv file, so you don't have to mess with writing TypeQL.
CSV FORMAT
Each row represents either an entity or a relationship.
3 columns are mandatory , the rest contain the attribute and role names defined in your schema.
-
ent_or_rel
- the script uses this to figure out if it's supposed to be making an entity or a relationship for this row of data. You can writeent
orentity
orrel
orrelation
. Capitalization doesn't matter- just the lettersent
andrel
. You can even writeentropy
and it'll recognize theent
as meaning this is an entity row. -
sub_type
- defines what kind of entity or relationship is in this row . For example, if you have aperson
entity type in your schema, and this row is for a person, then you putperson
there. -
alias
- this is the typeQL-style variable you will use to represent this entity. e.g.$x
. Each row must a unique one in this column .
Other Column Names
The rest of the column names must correspond to your schema's attributes
and roles
.
The values in your role columns ( in my example host
and client
) must correspond to the aliases you used when defining your entities.
Column order is not important. The script will figure out which columns contain attributes, and which ones contain info describing roles in a relationship.
Row order is
important, but no more than it is in any TypeQL script. Just make sure you define your entities before you start making links between them.
HOW TO USE
- Install the Python package
pandas
conda install pandas -y
orpip3 install pandas
- Have your database & schema created already. This only adds entities and relations to a pre-existing database with a schema loaded.
- Save this script somewhere on your computer. It has been tested with Python3.6, but it should work with any Python3.x. If it doesn't, let me know.
- EXECUTE THE SCRIPT LIKE THIS:
- $
python3 path/to/data.csv path/to/desired_script_name.tql
- $
- Launch your TypeDB console (method varies depending on your install)
> transaction
data write > source /path/to/desired_script_name.tql
> commit
Voila, your data is now in your database.