Skip to content

Commit 1467d3e

Browse files
committed
Replace non-URI safe characters when generating IDs
1 parent 4914aa1 commit 1467d3e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ const store = fortune({ ... }, {
5757
- `isNative`: Whether or not to use native bindings, requires `pg-native` module, which is an optional dependency of this one. Default: `false`.
5858
- `typeMap`: an object keyed by type name and valued by table name.
5959
- `primaryKeyType`: Data type of the primary key. May be `String`, `Number`, or a string for custom type. Default: `String`.
60-
- `generatePrimaryKey`: A function that accepts one argument, the `type` of the record, and returns either a `String` or `Number`. By default, it returns 15 random bytes, base64 encoded. Set this to a falsy value like `null` to turn this off.
60+
- `generatePrimaryKey`: A function that accepts one argument, the `type` of the record, and returns either a `String` or `Number`. By default,
61+
it returns 15 random bytes, base64 encoded in a URI-safe way. Set this to a falsey value like `null` to turn this off.
6162
- `useForeignKeys`: Whether or not to use foreign key constraint, optional since it will only be applied to non-array fields. Default: `false`.
6263

6364

lib/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function getCode (error) {
101101

102102
function defaultPrimaryKey () {
103103
return randomBytes(15).toString('base64')
104+
.replace(/\+/g, '-').replace(/\//g, '_')
104105
}
105106

106107

0 commit comments

Comments
 (0)