Server-side implementation of the MemberJunction Data Context system. Loads the data of sql-type DataContextItem objects by running their SQL through a query provider's screened ad-hoc path.
The @memberjunction/data-context-server package extends the base DataContextItem class from @memberjunction/data-context with a server-side implementation of LoadFromSQL. It runs the item's SQL through RunQuery({ SQL }) on a query provider, the same ad-hoc path ExecuteAdhocQuery uses, so the SQL must be a single read statement. On PostgreSQL that path also runs it in a read-only transaction that is rolled back. It never sends SQL to a raw connection pool. This is the server counterpart to the client-side GraphQL-based data context loading.
graph TD
A["DataContextItemServer"] -->|extends| B["DataContextItem
(data-context package)"]
A -->|"RunQuery({ SQL })"| C["Read-only query provider"]
C --> D["Database"]
E["Server-Side Code
(MJAPI, Actions, etc.)"] --> A
F["Client-Side Code
(Angular, React)"] --> G["DataContextItemClient
(GraphQL-based)"]
style A fill:#2d6a9f,stroke:#1a4971,color:#fff
style B fill:#7c5295,stroke:#563a6b,color:#fff
style C fill:#2d8659,stroke:#1a5c3a,color:#fff
style D fill:#2d8659,stroke:#1a5c3a,color:#fff
style E fill:#b8762f,stroke:#8a5722,color:#fff
style G fill:#b8762f,stroke:#8a5722,color:#fff
npm install @memberjunction/data-context-server
The package registers DataContextItemServer as a subclass of DataContextItem using MemberJunction's @RegisterClass decorator. When server-side code creates a DataContextItem, the class factory automatically returns the server implementation.
import '@memberjunction/data-context-server';
// DataContextItem instances can now load `sql` items on the server
The LoadFromSQL method:
IRunQueryProvider) as the data source. MJServer passes its read-only provider.DataContextItem.SQL through RunQuery({ SQL }) for the context user. The provider accepts only a single read statement.DataContextItem.DataDataLoadingErrorCallers decide who may run an item's SQL. MJServer's GetDataContextData and GetDataContextItemData queries allow it only for the data context's owner or an administrator, never for a scope-limited session, and only on the read-only provider.
| Package | Purpose |
|---|---|
@memberjunction/core |
IRunQueryProvider, UserInfo, LogError |
@memberjunction/global |
RegisterClass decorator |
@memberjunction/data-context |
Base DataContextItem class |
ISC