【发布时间】:2021-05-03 04:57:04
【问题描述】:
我们有一个市场,我们将用户搜索查询和请求日志存储到 API,以便我们以后可以使用这些数据深入了解客户行为。我们有一个重要的端点api/products,我们正在存储这个端点的所有请求有效负载。通过这个,我们可以知道正在搜索哪些条形码、品牌、供应商、搜索查询等。简而言之,这就像后端分析。
我正在为此使用 MySQL,但我不知道这是否是一个好方法,或者是否有其他开箱即用的解决方案。
以下类包含调用api/products 端点时请求可能具有的过滤器、查询等,我将其存储为JSON 类型在MySql 中。
注意:我们使用NodeJs 作为后端。
class GetProductsDto extends OffsetLimitDto {
@IsOptional()
@IsString()
@Trim()
@MaxLength(36)
outsourceId: string;
@IsOptional()
@IsString()
@Trim()
@MaxLength(48)
barcode: string;
@IsOptional()
@Type(() => Number)
@IsInt()
@IsPositive()
productCategoryId: number;
@IsOptional()
@Type(() => Number)
@IsInt()
@IsPositive()
supplierStoreId: number;
@IsOptional()
@Type(() => Number)
@IsInt()
@IsPositive()
manufacturerCompanyId: number;
@IsOptional()
@Type(() => Number)
@IsInt()
@IsPositive()
manufacturerCountryId: number;
@IsOptional()
@Expose({ name: 'quantity.gt', toPlainOnly: true })
@Type(() => Number)
@IsInt()
quantityGreaterThan: number;
@IsOptional()
@Expose({ name: 'quantity.lt', toPlainOnly: true })
@Type(() => Number)
@IsInt()
quantityLessThan: number;
@IsOptional()
@IsString()
@TrimAndRemoveConsecutiveSpaces()
@MaxLength(1000)
q: string;
@IsOptional()
@Type(() => Number)
@IsInt()
@IsPositive()
operationCityId: number;
@IsOptional()
@IsArray()
@ToDistinctArrayValues()
@ArrayMaxSize(Object.values(ProductIncludeFilter).length)
@IsEnum(ProductIncludeFilter, {
each: true,
message: `Array values should be one of [${Object.values(
ProductIncludeFilter,
)}]`,
})
include: ProductIncludeFilter[];
}
【问题讨论】:
标签: mysql node.js database analytics user-data