Skip to main content

Getting started

@pdftron/collab-sql-resolver-generator is a utility package that generates resolvers for you. It works with any database that uses an SQL-like query language, such as:

  • PostgreSQL
  • MSSQL
  • MySQL
  • SQLite3
  • Oracle

This package is intended to reduce the amount of work required to integrate the collaboration system.

How it works#

You must provide the module with the following information:

  • Database connection details
  • The names of your tables and columns
  • Date parsing logic

With this information, we are able to generate queries to read/write from your database. This is much faster than manually writing all these queries on your own.

Installation#

yarn add @pdftron/collab-sql-resolver-generator

Samples#

A sample project using this module can be viewed at https://github.com/PDFTron/webviewer-collab-sql-sample.

Example#

import CollabServer from '@pdftron/collab-server'
import SQLResolverGenerator from '@pdftron/collab-sql-resolver-generator'
const resolvers = SQLResolverGenerator({
// Provide which type of Database
client: 'pg',
// Provide database connection info
connection: {
host: 'localhost',
user: 'postgres',
password: 'admin',
database: 'collab'
},
// Provide information about your database
info: {
Users: {
// Tell us the name of your "users" table
table: "Users",
// Tell us the name of each column in the table
columns: {
id: 'Id',
userName: 'UserName',
email: 'Email',
type: 'Type',
createdAt: 'CreatedDate',
updatedAt: 'ModifiedDate'
}
},
Annotations: {
table: "Annotations",
columns: {
id: 'Id',
xfdf: 'Xfdf',
annotContents: 'Content',
authorId: 'CreatedByUserId',
annotationId: 'AnnotationId',
documentId: 'DocumentId',
pageNumber: 'PageNumber',
createdAt: 'CreatedDate',
updatedAt: 'ModifiedDate',
inReplyTo: 'InReplyTo',
}
},
Documents: {
table: 'Documents',
columns: {
id: 'Id',
authorId: 'CreatedByUserId',
isPublic: 'IsPublic',
name: 'DocumentName',
createdAt: 'CreatedDate',
updatedAt: 'ModifiedDate'
}
},
AnnotationMembers: {
table: 'AnnotationMembers',
columns: {
id: 'Id',
userId: 'CreatedByUserId',
documentId: 'DocumentId',
annotationId: 'MarkupId',
lastRead: 'LastRead',
createdAt: 'CreatedDate',
updatedAt: 'ModifiedDate',
annotationCreatedAt: 'MarkupCreatedDate'
}
},
DocumentMembers: {
table: 'MarkupDocuments',
columns: {
id: 'Id',
userId: 'CreatedByUserId',
documentId: 'DocumentId',
lastRead: 'LastRead',
createdAt: 'CreatedDate',
updatedAt: 'ModifiedDate'
}
},
Mentions: {
table: 'Mentions',
columns: {
id: 'Id',
userId: 'UserId',
documentId: 'DocumentId',
annotationId: 'MarkupId',
createdAt: 'CreatedDate',
updatedAt: 'ModifiedDate'
}
}
}
});
const server = new CollabServer({
resolvers
})
server.start(3000);

Next steps#