Create a Marvel Database with SQL and Javascript, the easy way

Since it is not a value, use wdt for this one.

By browsing that page you get a good idea about what are the properties you can use.

Pause: If you want to create a database but don’t know yet about what it will be, try the Random article function to get insights.

We can do the same thing for any Wikipedia page.

Go to the official Wikipedia website and search for anything, let’s say… Aluminium.

Now check the left-side bar and look for Wikidata item link.

Wikidata link is in read on the leftClick, and voilà, it shows all the attributes for this item.

We see we get the mass by using wdt:P2067, and many other attributes that may apply for other types of metal.

Each Wikidata entry has many properties.

The tooltip tells you the property ID.

Now that we have the Wikidata, we will:Create a query for an attribute of interestDownload the result as .

jsonAlways track the IDs (Wikidata item URL) and LabelsFor instance, I created one query for gender.

One query for occupation, and so on.

The result is a folder with many .

json files I will load in my database formed by many tables.

You could perform a single query with all the information.

In my case, I want it to be malleable, so I can perform JOIN, LEFT JOIN , and other SELECT commands to get different tables.

In fact, instead of getting only Marvel Universe, I discarded that filter and got a full database of instances of Fictional Characters (not only Comics Characters — for some reason this one would not query Captain America).

So, in my json files, you find Marvel, DC, and others.

The resulting jsons are found in my GitHub page.

Next, I will show how I used the json files with an easy SQL DB in Javascript.

As I mentioned in the last paragraph, my query is actually about the class Fictional Characters, and its sub-classes.

I also queried partners and spouses, so for this I used the command | to define two wdt:Note that in the above code I am not filtering for Marvel anymore.

For more complex queries or handling lists, please refer to the Wikidata website.

Another good option is the Help button at the top of the Wikidata Query Service where you can find examples and support.


Creating an SQL Database in JavascriptNow that we have the json files, let’s insert them into our SQL Database.

For this, we will use a tool named Alasql.

With Alasql, you can load data and create tables in different manners (read more here).

Here, since we have the jsons from Wikidata, we will apply a SELECT on each json (file) and insert into a new table in our database for easy access.

For simplification, my code will contain only two tables; you can find the complete updated version here.

It looks like this:We are set.

We have a database and can use it by calling let mydb = MarvelDB() and apply SQL commands like this: mydb.

exec('SELECT DISTINCT abilityLabel from abilities').


Final code and usageI defined some tests to make sure everything was working.

It exemplifies the usage of our database.

If you are not used to testing, just consider the let result = this.



) and console.

table(result) in the code below and ignore the other parts.

The above SELECT returns the column charLabel and renames to name.

It also joins the tables character, gender and abilities, making sure the entries have the same character id (char).

Finally, it filters by a specific gender named agender.

For more examples on this database, please go to the GitHub page – don’t forget to star it :)This article describes the way I created the database for the following visualization.

You can interact with it by accessing this website in a desktop/laptop (it may open in a mobile but the interaction is limited).

Marvel & DC visualization: https://heberleh.


io/comics-universe/Feel welcomed to add private notes and comments.

Thank you for reading my article!.

. More details

Leave a Reply