Configuration
This guide explains how to configure @pdftron/collab-sql-resolver-generator
in order to generate your resolvers.
#
Database type (required)The resolver generator needs to know which kind of database you are using. You can provide this data via the client
option. This option is required.
The possible values are as follows:
mysql
(MySQL)pg
(PostgreSQL)sqlite3
(SQLite)oracledb
(Oracle)mssql
(Microsoft SQL)
#
Database connection (required)The resolver generator also needs to know how to connect to your database in order to make read/writes. You can provide this information via the connection
option. This option is required.
This option can accept a number of different data types:
1) Connection object
You can provide connection details manually, like so:
The connection object accepts the following data (all optional):
host
(string) The hostname for your database. This can also be an entire connection string.user
(string) The username to use when connecting to your databasepassword
(string) The password to usedatabase
(string) The name of the databasefilename
(string) A filename for an SQLite3 adapter. See this guide for more info.socketPath
(string) Connect via unix domain socket. See this guide for more info.
2) Knex connection objects
This module uses Knex.js under the hood. This means that we can accept the same connection configuration that Knex accepts.
See this guide for info on what can be passed.
#
Database info (required)In order to generate queries, we need to know the names of your tables and the names of the columns that are relevant to collaboration.
This information can be passed via the info
parameter.
The info
object must contain 6 objects: Users
, Annotations
, Documents
, AnnotationMembers
, DocumentMembers
, and Mentions
. Each of these objects contains information on how to read/write data for the corresponding entity.
If you are using the snapshots feature, an additional 2 objects are required - Snapshots
and SnapshotAssets
.
important
For the purpose of these guides, we are going to call each of these objects table entities
#
Table entitiesEach table entity
should provide information on how to read/write data for that kind of entity. This includes the name of the table to query, the names of your columns, and any other additional transforms.
Each table entity
should contain the following information:
table
(string - required) The name of the table to querycolumns
(ColumnMap - required) Information about the columns to query. More info belowmiddleware
(Function[]) Additional transforms to apply to queries. More info here
For example, if you provide the following:
Whenever we need to get information about a user, we will generate a query that looks like this:
#
Column mapsA column map is an object that contains information about the columns in the corresponding table. Each table entity
requires different column information to be provided.
The names of these columns will be used when generating SQL queries.
Let's start by showing an example:
Each key in columns
represents a piece of data that we require, and each value represents which column in your database that data lives in.
So, for the above codeblock, if we need to get a user from their email, we would generate this query:
note
An object with a name
property can also be passed as well. This is useful when providing other column level options, such as transforms or joins.
All of the required information is documented below
#
All required column mapsUser column map
The user column map requires the following properties:
id
type
email
userName
(optional)createdAt
updatedAt
Example:
Annotation column map
The annotation column map requires the following properties:
id
xfdf
authorId
annotationId
documentId
pageNumber
createdAt
updatedAt
inReplyTo
annotContents
(optional)
Example:
Document column map
The document column map requires the following properties:
id
authorId
createdAt
updatedAt
isPublic
name
(optional)
Example:
Annotation Member column map
The annotation members column map requires the following properties:
id
userId
documentId
annotationId
lastRead
createdAt
updatedAt
annotationCreatedAt
Example:
Document Member column map
The document members column map requires the following properties:
id
userId
documentId
lastRead
createdAt
updatedAt
Example:
Mentions column map
The mentions column map requires the following properties:
id
userId
documentId
annotationId
createdAt
updatedAt
Example:
Snapshots column map (optional)
This is only required if using the snapshot feature.
The snapshots column map requires the following properties:
id
authorId
documentId
xfdf
name
createdAt
updatedAt
Example:
SnapshotAssets column map (optional)
This is only required if using the snapshot feature.
The snapshot assets column map requires the following properties:
id
snapshotId
data
createdAt
updatedAt