MCPcopy Create free account
hub / github.com/Permify/permify / ReadSchemaString

Method ReadSchemaString

internal/storage/postgres/schema_reader.go:82–118  ·  view source on GitHub ↗

ReadSchemaString returns the schema definition for a specific tenant and version as a string.

(ctx context.Context, tenantID, version string)

Source from the content-addressed store, hash-verified

80
81// ReadSchemaString returns the schema definition for a specific tenant and version as a string.
82func (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.
121func (r *SchemaReader) ReadEntityDefinition(ctx context.Context, tenantID, name, version string) (definition *base.EntityDefinition, v string, err error) {

Callers

nothing calls this directly

Implementers 7

NoopSchemaReaderinternal/storage/storage.go
SchemaReaderinternal/storage/proxies/cache/schema_
SchemaReaderinternal/storage/proxies/circuitbreake
SchemaReaderinternal/storage/proxies/singleflight/
SchemaReaderinternal/storage/postgres/schema_reade
SchemaReaderinternal/storage/memory/schema_reader.
mockSchemaReaderinternal/engines/lookup_test.go

Calls 5

SerializedMethod · 0.95
HandleErrorFunction · 0.92
StartMethod · 0.80
CloseMethod · 0.65
ScanMethod · 0.45

Tested by

no test coverage detected