Integrating with an existing database
The WebViewer Collaboration modules are intended to work with existing databases and data. The following guides outline the recommended approach to integrate with an existing database.
WebViewer Collaboration reads and writes data through functions called "resolvers". If you have worked with GraphQL before, you may be familiar with this concept.
Before continuing with this guide, we recommend learning about resolvers by reading this guide.
Resolvers are what allows us to integrate with an existing database. Resolvers do not care about how data is read/write, which leaves the implementation and database structure up to you!
Your resolvers are required to be able to read/write all the data specified here. The server does not care about how that data is fetched, - it only cares about what is returned from the function. This leaves the database implementation totally up to you.
Changes to your database may be required to make it work with the data structure that WebViewer Collaboration expects. As long as you are able to read and write all the required data, the structure of your database does not matter.
In most cases, missing columns in your database can simply be added.
For example, if your existing "Documents" table does not have the
isPublic property that WebViewer Collaboration expects to exist, you can just add this column and set the default value to
false. If you don't plan on using the public documents feature, you could also just hard code your resolver to return
false for this property which requires no database changes!
There may also be times where the required data does exist, but it exists in a different table as a foreign key reference. In this case, you can write a join query to fetch all the data required.
If you are missing an entire table that WebViewer Collaboration expects, you can simply just add it. You can take a look at the data types guide to see what tables are required, as well as their structure.
#Incompatible data types
If the data type in your database is incompatible with what WebViewer Collaboration expects, you can simply transform that data directly in your resolvers.
For example, WebViewer Collaboration expects all timestamps to be a number (unix timestamp) - however, if your database stores timestamps as ISO strings, you will need to transform that data before returning it. Here is an example:
#Integrating with an SQL-like database
If you are using one of the following database:
then we recommend using our SQL resolver generator package to integrate into your database.
This package requires you to provide the name of your tables of columns in your database, and in return, generates resolvers.
If you are stuck on implementing your existing database with WebViewer Collaboration, write to us on our community forum and we will be happy to help!