chiselstrike
chiselstrike copied to clipboard
blob type to store images
I need to store images in sqlite, and currently using String field for it, how can use blob instead?
@7flash There's no API to do blobs, but I am actually working on it. But now we're debating with @honzasp whether the mapping type should be Blob
or ArrayBuffer
. What's your take on this @7flash?
Deno defines Blob as
type BlobPart = BufferSource | Blob | string;
type BufferSource = ArrayBufferView | ArrayBuffer;
class Blob {
constructor(blobParts?: BlobPart[], options?: BlobPropertyBag);
stream(): ReadableStream<Uint8Array>;
text(): Promise<string>;
arrayBuffer(): Promise<ArrayBuffer>;
// ...
}
that means it can be instantiated by passing an instance of ArrayBuffer in constructor and have it extracted as arrayBuffer()
But, Blob type in MySQL is actually just text, therefore ".text()" should be called on each field of Blob type asynchronously before saving the item into database?
I see this as part of #1748 .
@BearLemma do we depend on adding reflection to do this right ?
Well if it's just about storing ArrayBuffers then I don't think so :thinking: . At least not in the general sense. We've been discussing that in that RFC on next-gen data model.
@7flash We are working on Blob
support right now. It's part of our Kafka producer effort, but should work for this use case too. Will update this ticket when the work lands in main
hopefully in the next few weeks.
@7flash with https://github.com/chiselstrike/chiselstrike/pull/1785 we've just landed the support for ArrayBuffer
as entity field. I think it should be trivially possible to convert Blob to ArrayBuffer and store it that way. Is it going to solve your problem?
@7flash with #1785 we've just landed the support for
ArrayBuffer
as entity field. I think it should be trivially possible to convert Blob to ArrayBuffer and store it that way. Is it going to solve your problem?
I am still storing images in String field.. is that very wrong? will it affect performance or anything if change to ArrayBuffer?
@7flash with #1785 we've just landed the support for
ArrayBuffer
as entity field. I think it should be trivially possible to convert Blob to ArrayBuffer and store it that way. Is it going to solve your problem?I am still storing images in String field.. is that very wrong? will it affect performance or anything if change to ArrayBuffer?
Not really very wrong :) just less efficient. ArrayBuffer
will get stored as binary blob which is more efficient. In addition to that, you get the blobs base64
encoded when accessed via CRUD API which I think is particularly useful for images.
I can see that Blobs were implemented internally, but should I still keep using string type for images? When I try to define a Blob field in model, it doesn't seem to recognize it:
field 'image' in class 'FortyEight' is of unknown entity type 'Blob'
@7flash As I wrote, you need to use the ArrayBuffer
type. That should work fine.