# API reference (/docs/composer/api-reference) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Signatures, options, and return values of compute(), rawPostgres(), postgres(), and dataContract() in @prisma/composer-prisma-cloud 0.41.2. Location: Composer > API reference These are the functions you declare a service and its database with, as `@prisma/composer-prisma-cloud` 0.41.2 types them. `compute()` and `rawPostgres()` come from the package root, and `postgres()` and `dataContract()` from `@prisma/composer-prisma-cloud/orm`: ```ts import { compute, rawPostgres } from '@prisma/composer-prisma-cloud'; import { dataContract, postgres } from '@prisma/composer-prisma-cloud/orm'; ``` The functions that wire an app together are documented with the concepts: `appRoot()`, `module()` and `provision()` in [Apps and Modules](https://www.prisma.io/docs/composer/apps-and-modules), and `contract()` and `rpc()` in [Services and contracts](https://www.prisma.io/docs/composer/services-and-contracts). An app is a tree of modules. The root module, built with `appRoot()`, is the app itself, and a Module, built with `module()`, is a reusable group of services and databases inside it. A module provisions a service or a database when it adds it to the app with `provision()`. `rawPostgres()` and `postgres()` each have two forms. Called with an options object that has a `name`, they declare the database itself, which a module provisions. Called with no arguments, `rawPostgres()`, or with only the contract, `postgres(contract)`, they declare that a service needs a database, and the call goes in the service's `deps`. [Databases](https://www.prisma.io/docs/composer/databases) shows both ends wired together. ## `compute()` [#compute] Declares a service that runs on Prisma Compute. ```ts compute(def: { name: string; deps: D; input?: I; build: BuildAdapter; expose?: E; listens?: boolean; }): ComputeService ``` | Option | Type | Required | Description | | --------- | ----------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `name` | `string` | Yes | The service's name. See the note below the table. | | `deps` | An object with one dependency per key, such as `{ db: rawPostgres() }` | Yes | What the service needs from the rest of the app. Pass `{}` for nothing. See the list below the table. | | `input` | A [Standard Schema](https://standardschema.dev), such as an ArkType `type({ ... })` | No | The service's configuration and credentials as one schema. Leave it out for a service that takes none. See [Service input](https://www.prisma.io/docs/composer/service-input). | | `build` | A build adapter | Yes | Where the service's built output is. See the note below the table. | | `expose` | An object with one interface per key, such as `{ http: rawHttpContract }` | No | What the service offers the rest of the app. A value is an RPC contract built with `contract()` from `@prisma/composer/service-rpc`, or `rawHttpContract` from `@prisma/composer/http` for plain HTTP. Default: nothing. | | `listens` | `boolean` | No | Whether the service listens on its port. Set `false` for a service that never receives requests, such as a scheduler. Default: `true`. | Composer refers to the service by its address: the app's name, the name of each Module the service is in, and the service's name, joined with dots, such as `my-app.quotes`. `prisma dev url` takes the address as it is, such as `npx prisma dev url my-app.quotes`, and the platform commands take it with `@` in front; the [`deploy list`](https://www.prisma.io/docs/cli/deploy#deploy-list) section lists them. When the module that provisions the service passes an `id`, as in `provision(quotesService, { id: 'api', deps: { db } })`, the address ends in that `id` instead of `name`: `my-app.api`. A value in `deps` is one of these: - `rawPostgres()` or `postgres(contract)`, for a database, as described below. - `rpc(contract)` from `@prisma/composer/service-rpc`, for another service's RPC contract. See [Services and contracts](https://www.prisma.io/docs/composer/services-and-contracts). - `rawHttp()` from `@prisma/composer/http`, for another service's plain HTTP. - A dependency function that comes with a ready-made Module, such as those in [Building blocks](https://www.prisma.io/docs/composer/building-blocks). The build adapter for a server you bundle into one file yourself is the default export of `@prisma/composer/node`, imported as `node`: `node({ module: import.meta.url, entry: '../dist/server.mjs' })`. `module: import.meta.url` tells the adapter where the declaration file is, and `entry` is the built file, relative to that file. Composer does not build the service: it runs what your build wrote, and `entry` must be one self-contained file, as [Build](https://www.prisma.io/docs/composer/getting-started#5-build) explains. For a Next.js app, use `nextjs()` from `@prisma/composer/nextjs`; [Porting an app](https://www.prisma.io/docs/composer/porting-an-app) shows it in use. ### What `compute()` returns [#what-compute-returns] `compute()` returns a `ComputeService`, which a module provisions with `provision()`. `provision()` returns an object with one property per key of `expose`, such as `quotes.http` for `expose: { http: rawHttpContract }`. You pass that property to another service's `deps`, or as the `target` of a public URL declared with [`publicUrl()`](https://www.prisma.io/docs/composer/deploying#make-a-service-public); see [The root module](https://www.prisma.io/docs/composer/apps-and-modules#the-root-module). The service's own code imports the same value and calls these methods on it: | Method | Returns | Description | | ---------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `load()` | An object with one value per key of `deps` | The dependencies, ready to use, such as `{ db }` for `deps: { db: rawPostgres() }`. A second call returns the same object. | | `input()` | The value of the `input` schema | The service's input, parsed and checked against the schema. A field declared with `secretString()`, from `@prisma/composer/arktype` or `@prisma/composer/zod`, arrives as a `SecretString`, which prints as `[REDACTED]`; call `.expose()` on it to get the text. | | `port()` | `number` | The port the service listens on. `3000` when the platform sets none. | | `origin()` | `string` | The origin the platform gives the service, such as `https://xyz.ewr.prisma.build`. | Call these methods in the code the service runs, under `prisma dev` or on Prisma Compute, such as the top level of its server file. In unit tests, `mockService` supplies what `load()` and `input()` return, and `bootstrapService` also sets the port; see [Testing](https://www.prisma.io/docs/composer/testing). ### Example [#example] The service declaration, with a [`postgres()`](#postgres) database and the data contract from [`dataContract()`](#datacontract): ```ts title="src/service.ts" import { rawHttpContract } from '@prisma/composer/http'; import node from '@prisma/composer/node'; import { compute } from '@prisma/composer-prisma-cloud'; import { postgres } from '@prisma/composer-prisma-cloud/orm'; import { quotesData } from './data.ts'; export default compute({ name: 'quotes', deps: { db: postgres(quotesData) }, build: node({ module: import.meta.url, entry: '../dist/server.mjs' }), expose: { http: rawHttpContract }, }); ``` The server, which `bun build src/server.ts --target=bun --outfile dist/server.mjs` bundles into the file `entry` names: ```ts title="src/server.ts" import service from './service.ts'; const { db } = service.load(); Bun.serve({ port: service.port(), fetch: async () => Response.json(await db.client.orm.public.Quote.all()), }); ``` `Bun.serve` listens on every network interface by default, which Prisma Compute needs because requests reach the service from outside its machine. ## `rawPostgres()` [#rawpostgres] A Prisma Postgres database that gives the service only a connection string. Composer never creates or changes its tables. ### Declare the database [#declare-the-database] ```ts rawPostgres(opts: { name: string }): ResourceNode ``` | Option | Type | Required | Description | | ------ | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- | | `name` | `string` | Yes | The database's name, such as `'database'`. [The root module](https://www.prisma.io/docs/composer/apps-and-modules#the-root-module) lists the naming rules. | Returns the database, which the root module or a Module provisions: `const db = provision(rawPostgres({ name: 'database' }))`. ### Declare that a service needs one [#declare-that-a-service-needs-one] ```ts rawPostgres(): DependencyEnd ``` It takes no options, and `load()` returns this value for it: | Field | Type | Description | | ----- | -------- | ---------------------------------------------------- | | `url` | `string` | The connection string, for your own Postgres client. | ### Example [#example-1] ```ts title="module.ts" import { appRoot } from '@prisma/composer'; import { rawPostgres } from '@prisma/composer-prisma-cloud'; import quotesService from './src/quotes/service.ts'; export default appRoot('my-app', ({ provision }) => { const db = provision(rawPostgres({ name: 'database' })); provision(quotesService, { deps: { db } }); }); ``` ## `postgres()` [#postgres] A Prisma Postgres database whose tables a Prisma ORM data contract describes. The data contract is your schema, written in `contract.prisma`, plus the `contract.json` and `contract.d.ts` that `npx prisma contract emit` writes from it; see [The data contract](https://www.prisma.io/docs/orm/contract-authoring/the-data-contract). You write migrations with `npx prisma migration plan`, and Composer migrates the database to its `targetRef` under `prisma dev` and on every deploy. The [database example](https://www.prisma.io/docs/composer/databases#example-an-http-api-that-reads-and-writes-a-table) goes through each step. ### Declare the database [#declare-the-database-1] ```ts postgres(opts: { name: string; contract: PostgresContract; config: string; targetRef: string | Value; }): PostgresResourceNode ``` | Option | Type | Required | Description | | ----------- | ----------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | `string` | Yes | The database's name, such as `'database'`. [The root module](https://www.prisma.io/docs/composer/apps-and-modules#the-root-module) lists the naming rules. | | `contract` | The value `dataContract()` returns | Yes | The data contract the database follows. Every service that uses the database declares the same value. | | `config` | `string` | Yes | The `prisma.config.ts` whose `orm` section names the contract, such as `'./prisma.config.ts'`. [Configuration](https://www.prisma.io/docs/cli/configuration) shows the `orm` section. | | `targetRef` | `string`, or a `Value` from `resolve()` | Yes | What every deploy and every `prisma dev` run migrates the database to: the name of a [ref](https://www.prisma.io/docs/cli/migration-ref), a file in `migrations/app/refs/` that names a contract, or `'@contract'`, the contract this commit emits. See the note below the table. | `Value` is the type [`resolve()`](https://www.prisma.io/docs/composer/service-input#values-that-differ-per-environment) returns, exported from `@prisma/composer`: a string the deploy computes, such as one derived from the environment's name. Every deploy, and every time `prisma dev` starts or applies a rebuild, runs the equivalent of `prisma db migrate --to ` against the database. Nothing else is accepted: `@empty`, `@db`, a contract hash, and a migration directory name are refused: when the node is declared, or, for a value from `resolve()`, when the deploy runs. A deploy to an environment whose ref file does not exist fails with `MIGRATION.UNKNOWN_REF`. An app that deploys to several environments usually computes the ref from the environment's name, so each environment migrates to its own ref and `prisma dev`, whose environment is `dev`, migrates to the contract you emit: ```ts targetRef: resolve([environment.name], ([name]) => (name === 'dev' ? '@contract' : name)), ``` A Module that provisions its own database uses `'@contract'`, because its migrations ship inside its package and the app cannot commit refs for it. A ref can also declare [policies](https://www.prisma.io/docs/orm/migrations/database-policies), rules that limit how the database may change. When they differ from the database's, the deploy fails with `MIGRATION.POLICY_MISMATCH`; see [When a deploy refuses a ref's policies](https://www.prisma.io/docs/composer/deploying#when-a-deploy-refuses-a-refs-policies). Returns the database, which the root module or a Module provisions with `provision()`. ### Declare that a service needs one [#declare-that-a-service-needs-one-1] ```ts postgres(contract: PostgresContract): DependencyEnd ``` | Parameter | Type | Required | Description | | ---------- | ---------------------------------- | -------- | ------------------------------------------------------------------------------------------------ | | `contract` | The value `dataContract()` returns | Yes | The data contract the service queries. It must be the same value the database was declared with. | `load()` returns this value for it: | Field | Type | Description | | --------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `url` | `string` | The connection string. | | `client` | The typed Prisma ORM client | A client with default options. Query a model with `db.client.orm.public.`, where `public` is the PostgreSQL schema and `` is the model's name as `contract.prisma` writes it, such as `db.client.orm.public.Quote.all()`. | | `clientWith(options)` | A function that returns a typed Prisma ORM client | Creates a client with Prisma ORM options, such as `extensions` or `middleware`. Every option except `poolOptions` is accepted. Call it once, at the top level of your server file. | | `connection` | A connection pool | The pool, for a Prisma ORM client you create yourself: pass it as that client's `binding` option, which tells the client which database to use; see [Transactions and runtime](https://www.prisma.io/docs/orm/reference/transactions-and-runtime). | `client`, `clientWith()`, and `connection` share one connection pool. ### Example [#example-2] The root module declares the database and wires it into the service from the [`compute()` example](#example): ```ts title="module.ts" import { appRoot, resolve } from '@prisma/composer'; import { postgres } from '@prisma/composer-prisma-cloud/orm'; import { quotesData } from './src/data.ts'; import quotesService from './src/service.ts'; export default appRoot('quotes-app', ({ environment, provision }) => { const db = provision( postgres({ name: 'database', contract: quotesData, config: './prisma.config.ts', targetRef: resolve([environment.name], ([name]) => (name === 'dev' ? '@contract' : name)), }), ); provision(quotesService, { deps: { db } }); }); ``` The [database example](https://www.prisma.io/docs/composer/databases#example-an-http-api-that-reads-and-writes-a-table) adds the server code that queries the database, the schema, the migrations, and how to run it. ## `dataContract()` [#datacontract] Wraps a Prisma ORM data contract so `postgres()` can use it. ```ts dataContract(contractJson: unknown): PostgresContract ``` | Parameter | Type | Required | Description | | -------------- | ---------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------- | | `Contract` | Type argument | No, but needed to type the client | The `Contract` type that `contract.d.ts` exports. Without it, the client is not typed by your schema. | | `contractJson` | The imported `contract.json` | Yes | The contract. | Run `npx prisma contract emit` after each change to `contract.prisma`. It writes `contract.json` and `contract.d.ts` next to it; see [`contract emit`](https://www.prisma.io/docs/cli/contract-emit). ### Example [#example-3] ```ts title="src/data.ts" import { dataContract } from '@prisma/composer-prisma-cloud/orm'; import type { Contract } from '../contract.d.js'; import contractJson from '../contract.json' with { type: 'json' }; export const quotesData = dataContract(contractJson); ``` ## Related pages - [Apps and Modules](https://www.prisma.io/docs/composer/apps-and-modules): How services, resources, and Modules compose into a Prisma App, and how provision() wires them together. - [Building blocks](https://www.prisma.io/docs/composer/building-blocks): Compose the ready-made cron, storage, and streams Modules instead of building scheduled jobs, blob storage, or event streams yourself. - [Core concepts](https://www.prisma.io/docs/composer/core-concepts): The ideas every Composer declaration and command builds on: services, resources, Modules, ports, contracts, environments, and the deploy model. - [Databases](https://www.prisma.io/docs/composer/databases): Give a service a Postgres database, either as a plain connection or typed by a Prisma ORM contract with managed migrations. - [Deploying](https://www.prisma.io/docs/composer/deploying): Deploy a Prisma App to production or another environment, run it in CI, and tear environments down safely.