ReadSchemaString returns the schema definition for a specific tenant and version as a string.
(ctx context.Context, tenantID, version string)
| 80 | |
| 81 | // ReadSchemaString returns the schema definition for a specific tenant and version as a string. |
| 82 | func (r *SchemaReader) ReadSchemaString(ctx context.Context, tenantID, version string) (definitions []string, err error) { |
| 83 | ctx, span := internal.Tracer.Start(ctx, "schema-reader.read-schema-string") |
| 84 | defer span.End() |
| 85 | slog.DebugContext(ctx, "reading schema", slog.Any("tenant_id", tenantID), slog.Any("version", version)) |
| 86 | builder := r.database.Builder.Select("name, serialized_definition, version").From(SchemaDefinitionTable).Where(squirrel.Eq{"version": version, "tenant_id": tenantID}) |
| 87 | |
| 88 | var query string |
| 89 | var args []interface{} |
| 90 | |
| 91 | query, args, err = builder.ToSql() |
| 92 | if err != nil { |
| 93 | return []string{}, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SQL_BUILDER) |
| 94 | } |
| 95 | |
| 96 | slog.DebugContext(ctx, "executing sql query", slog.Any("query", query), slog.Any("arguments", args)) |
| 97 | var rows pgx.Rows |
| 98 | rows, err = r.database.ReadPool.Query(ctx, query, args...) |
| 99 | if err != nil { |
| 100 | return []string{}, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_EXECUTION) |
| 101 | } |
| 102 | defer rows.Close() |
| 103 | |
| 104 | for rows.Next() { |
| 105 | sd := storage.SchemaDefinition{} |
| 106 | err = rows.Scan(&sd.Name, &sd.SerializedDefinition, &sd.Version) |
| 107 | if err != nil { |
| 108 | return []string{}, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SCAN) |
| 109 | } |
| 110 | definitions = append(definitions, sd.Serialized()) |
| 111 | } |
| 112 | if err = rows.Err(); err != nil { |
| 113 | return []string{}, utils.HandleError(ctx, span, err, base.ErrorCode_ERROR_CODE_SCAN) |
| 114 | } |
| 115 | |
| 116 | slog.DebugContext(ctx, "successfully retrieved", slog.Any("schema definitions", len(definitions))) |
| 117 | return definitions, err |
| 118 | } |
| 119 | |
| 120 | // ReadEntityDefinition - Reads entity config from the repository. |
| 121 | func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, version string) (definition *base.EntityDefinition, v string, err error) { |
nothing calls this directly
no test coverage detected