Generates a mapper that, given a primary key definition is able to produce the primary key for that item.
Type parameters
Type parameter |
---|
Fields extends FieldsStructure |
PrimaryKey extends keyof Fields |
Constructors
new FormattedPrimaryKey()
new FormattedPrimaryKey<Fields, PrimaryKey>(...elements): FormattedPrimaryKey<Fields, PrimaryKey>
Parameters
Parameter | Type |
---|---|
...elements | PrimaryKey [] |
Returns
FormattedPrimaryKey
<Fields
, PrimaryKey
>
Properties
elements
readonly elements: PrimaryKey[];
Methods
forItem()
forItem(item): string
Generate the serialized form of the item's primary key.
For single value primary keys, the encoded values are just the json representation of the primary
key. For example, if the primary key is ['id'] the following table shows encodings:
type | value | encoded |
---|---|---|
number | 15 | new Map([["15", ...], ...]) |
boolean | false | new Map([["false", ...], ...]) |
string | "hello" | new Map([['"hello"', ...], ...]) |
Take note of the extra quotes in the string case.
For primary keys with multiple values, first sort the array of primary keys then join the json encoded values
from of the keys with commas. For example:
primary key = ["lastName", "firstName"]
sorted key = ["firstName", "lastName"]
row = {"lastName": "Smith", "firstName": "John", "age": 42}
row key = '"John","Smith"'
items = new Map([['"John","Smith"', {"lastName": "Smith", "firstName": "John", "age": 42}]])
Parameters
Parameter | Type |
---|---|
item | PartialItemType <Fields , PrimaryKey > |
Returns
string
serializeList()
static serializeList(items): string
Parameters
Parameter | Type |
---|---|
items | unknown [] |
Returns
string