> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/schema/field-types/integer.md).

# Integer

A whole-number field with minimum, maximum, default and unique; shown as a number input.

An **Integer** field stores a whole number — a count, a year, a quantity. The data schema sets the allowed range.

**Builder:** Form fields panel → **Number** · widget `number` · data type `integer.schema.v1`

## Data schema

```json
{
  "pages": {
    "type": "integer",
    "minimum": 1,
    "maximum": 5000,
    "default": 100
  }
}
```

| Keyword   | Required | What it does                                                                                                                                                                | Example     |
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `type`    | yes      | Always `"integer"`.                                                                                                                                                         | `"integer"` |
| `minimum` | no       | The smallest value allowed. Must stay **below 16777216** — an integer field with a bigger minimum is read as a [Date](/codemash/cloud/database/schema/field-types/date.md). | `1`         |
| `maximum` | no       | The largest value allowed.                                                                                                                                                  | `5000`      |
| `default` | no       | The value a new record gets when the field is left out.                                                                                                                     | `100`       |
| `unique`  | no       | `true` = no two records share the value.                                                                                                                                    | `true`      |

### What the server refuses

Every write — insert, update, replace; from Cloud, the API, an SDK, the CLI or an AI agent — is checked against the published schema. A broken value is answered with one error per field: the code, and `Field '<name>' is invalid: <reason>`. Nothing is written.

| Case                                  | Code                     | The reason it gives    |
| ------------------------------------- | ------------------------ | ---------------------- |
| a required field is missing or `null` | `CM-ERRORS-DATABASE-030` | `a value is required`  |
| not an integer (a string, `2.5`, …)   | `CM-ERRORS-DATABASE-039` | `must be an integer`   |
| below `minimum`                       | `CM-ERRORS-DATABASE-043` | `must be at least 1`   |
| above `maximum`                       | `CM-ERRORS-DATABASE-043` | `must be at most 5000` |

A keyword that is not in the table above is refused when the schema is **saved**, not when a record is written: `CM-ERRORS-SCHEMA-010` — `Data schema violates meta-schema: Property 'sort' has not been defined and the schema does not allow additional properties. Path 'properties.pages.sort' (field 'properties.pages' checked as integer.schema.v1).`

Also refused at save time:

* `minimum` above `maximum`, or a keyword outside the integer range (`1e300`) — `CM-ERRORS-SCHEMA-022` `Schema field 'pages' has an invalid range: …`.
* a `default` outside the range — `CM-ERRORS-SCHEMA-037`.

## UI schema

The cell uses the `number` widget. The same field shown as stars is the [Rating](/codemash/cloud/database/schema/field-types/rate.md) widget.

```json
{
  "colSpan": 4,
  "element": {
    "fieldId": "pages",
    "meta": { "widget": "number", "label": "Pages", "placeholder": "387" }
  }
}
```

Every cell also takes the common layout options: `label`, `placeholder`, `help` (the text under the input), `required`, `readonly` and `hidden`. Keys outside this list — `watermark`, `hint`, `permissions` — are refused when the schema is saved (`CM-ERRORS-SCHEMA-012`), see [Schema authoring guide](/codemash/cloud/database/schema.md#one-contract-no-second-dialect).

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-6319b8c01b4c7c41c3221641516b145e6b57df60%2Ffield-types-numbers-1.png?alt=media" alt="Add New Record form of sc_e2e_all_types, Numbers tab: decimal inputs (Decimal plain, type, minimum, maximum, step, default), a Decimal unique box, and currency inputs with a USD or EUR currency selector in front of the amount"><figcaption><p>The Numbers tab of the generated all-types form: number and currency widgets.</p></figcaption></figure>

## Records

A record the schema accepts:

```json
{ "pages": 387 }
```

A record it refuses:

```json
{ "pages": 0 }
```

The answer: `CM-ERRORS-DATABASE-043` — `Field 'pages' is invalid: must be at least 1`. In Cloud the same sentence is shown under the field before the form is sent; the server repeats the check on every API write.

## Good to know

* Integer and [Date](/codemash/cloud/database/schema/field-types/date.md) share `type: "integer"`; the `minimum` keyword tells them apart (a date requires `minimum` ≥ 16777216).
* A decimal value such as `2.5` is refused with `must be an integer` — use a [Decimal](/codemash/cloud/database/schema/field-types/decimal.md) field for fractions.

## Do it from code

```ts
await norbix.api.database.insertOne({
  collectionName: 'books',
  document: JSON.stringify({ pages: 387 }),
});
```

```sh
norbix api database one insert --collectionName books --document '{"pages":387}'
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Save Database Schema](/codemash/api-reference/database/schemas/save-database-schema.md)

## Related

[Decimal](/codemash/cloud/database/schema/field-types/decimal.md) · [Rating](/codemash/cloud/database/schema/field-types/rate.md) · [Date and date-time](/codemash/cloud/database/schema/field-types/date.md) · [Field type reference](/codemash/cloud/database/schema/field-types.md) · [Schema authoring guide](/codemash/cloud/database/schema.md) · [Create a schema](/codemash/cloud/database/collections/create-schema.md)
