New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): add custom types for array, blob and json #559
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B4nan
added a commit
that referenced
this pull request
May 21, 2020
### ArrayType In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the values into string separated by commas. This means that you can't use values that contain comma with the `ArrayType` (but you can create custom array type that will handle this case, e.g. by using different separator). By default array of strings is returned from the type. You can also have arrays of numbers or other data types - to do so, you will need to implement custom `hydrate` method that is used for converting the array values to the right type. ```typescript @Property({ type: new ArrayType(i => +i), nullable: true }) array?: number[]; ``` ### BlobType Blob type can be used to store binary data in the database. ```typescript @Property({ type: BlobType, nullable: true }) blob?: Buffer; ``` ### JsonType To store objects we can use `JsonType`. As some drivers are handling objects automatically and some don't, this type will handle the serialization in a driver independent way (calling `parse` and `stringify` only when needed). ```typescript @Property({ type: JsonType, nullable: true }) object?: { foo: string; bar: number }; ``` Related: #476
B4nan
added a commit
that referenced
this pull request
Jun 1, 2020
### ArrayType In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the values into string separated by commas. This means that you can't use values that contain comma with the `ArrayType` (but you can create custom array type that will handle this case, e.g. by using different separator). By default array of strings is returned from the type. You can also have arrays of numbers or other data types - to do so, you will need to implement custom `hydrate` method that is used for converting the array values to the right type. ```typescript @Property({ type: new ArrayType(i => +i), nullable: true }) array?: number[]; ``` ### BlobType Blob type can be used to store binary data in the database. ```typescript @Property({ type: BlobType, nullable: true }) blob?: Buffer; ``` ### JsonType To store objects we can use `JsonType`. As some drivers are handling objects automatically and some don't, this type will handle the serialization in a driver independent way (calling `parse` and `stringify` only when needed). ```typescript @Property({ type: JsonType, nullable: true }) object?: { foo: string; bar: number }; ``` Related: #476
B4nan
added a commit
that referenced
this pull request
Jun 5, 2020
### ArrayType In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the values into string separated by commas. This means that you can't use values that contain comma with the `ArrayType` (but you can create custom array type that will handle this case, e.g. by using different separator). By default array of strings is returned from the type. You can also have arrays of numbers or other data types - to do so, you will need to implement custom `hydrate` method that is used for converting the array values to the right type. ```typescript @Property({ type: new ArrayType(i => +i), nullable: true }) array?: number[]; ``` ### BlobType Blob type can be used to store binary data in the database. ```typescript @Property({ type: BlobType, nullable: true }) blob?: Buffer; ``` ### JsonType To store objects we can use `JsonType`. As some drivers are handling objects automatically and some don't, this type will handle the serialization in a driver independent way (calling `parse` and `stringify` only when needed). ```typescript @Property({ type: JsonType, nullable: true }) object?: { foo: string; bar: number }; ``` Related: #476
B4nan
added a commit
that referenced
this pull request
Jun 16, 2020
### ArrayType In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the values into string separated by commas. This means that you can't use values that contain comma with the `ArrayType` (but you can create custom array type that will handle this case, e.g. by using different separator). By default array of strings is returned from the type. You can also have arrays of numbers or other data types - to do so, you will need to implement custom `hydrate` method that is used for converting the array values to the right type. ```typescript @Property({ type: new ArrayType(i => +i), nullable: true }) array?: number[]; ``` ### BlobType Blob type can be used to store binary data in the database. ```typescript @Property({ type: BlobType, nullable: true }) blob?: Buffer; ``` ### JsonType To store objects we can use `JsonType`. As some drivers are handling objects automatically and some don't, this type will handle the serialization in a driver independent way (calling `parse` and `stringify` only when needed). ```typescript @Property({ type: JsonType, nullable: true }) object?: { foo: string; bar: number }; ``` Related: #476
B4nan
added a commit
that referenced
this pull request
Aug 2, 2020
### ArrayType In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the values into string separated by commas. This means that you can't use values that contain comma with the `ArrayType` (but you can create custom array type that will handle this case, e.g. by using different separator). By default array of strings is returned from the type. You can also have arrays of numbers or other data types - to do so, you will need to implement custom `hydrate` method that is used for converting the array values to the right type. ```typescript @Property({ type: new ArrayType(i => +i), nullable: true }) array?: number[]; ``` ### BlobType Blob type can be used to store binary data in the database. ```typescript @Property({ type: BlobType, nullable: true }) blob?: Buffer; ``` ### JsonType To store objects we can use `JsonType`. As some drivers are handling objects automatically and some don't, this type will handle the serialization in a driver independent way (calling `parse` and `stringify` only when needed). ```typescript @Property({ type: JsonType, nullable: true }) object?: { foo: string; bar: number }; ``` Related: #476
B4nan
added a commit
that referenced
this pull request
Aug 9, 2020
### ArrayType In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the values into string separated by commas. This means that you can't use values that contain comma with the `ArrayType` (but you can create custom array type that will handle this case, e.g. by using different separator). By default array of strings is returned from the type. You can also have arrays of numbers or other data types - to do so, you will need to implement custom `hydrate` method that is used for converting the array values to the right type. ```typescript @Property({ type: new ArrayType(i => +i), nullable: true }) array?: number[]; ``` ### BlobType Blob type can be used to store binary data in the database. ```typescript @Property({ type: BlobType, nullable: true }) blob?: Buffer; ``` ### JsonType To store objects we can use `JsonType`. As some drivers are handling objects automatically and some don't, this type will handle the serialization in a driver independent way (calling `parse` and `stringify` only when needed). ```typescript @Property({ type: JsonType, nullable: true }) object?: { foo: string; bar: number }; ``` Related: #476
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ArrayType
In PostgreSQL and MongoDB, it uses native arrays, otherwise it concatenates the
values into string separated by commas. This means that you can't use values that
contain comma with the
ArrayType
(but you can create custom array type that willhandle this case, e.g. by using different separator).
By default array of strings is returned from the type. You can also have arrays
of numbers or other data types - to do so, you will need to implement custom
hydrate
method that is used for converting the array values to the right type.BlobType
Blob type can be used to store binary data in the database.
JsonType
To store objects we can use
JsonType
. As some drivers are handling objectsautomatically and some don't, this type will handle the serialization in a driver
independent way (calling
parse
andstringify
only when needed).Related: #476