X Tutup
using System; using System.Collections.Generic; namespace Npgsql; /// /// Options for configuring Npgsql type loading. /// sealed class NpgsqlTypeLoadingOptions { /// /// Load table composite type definitions, and not just free-standing composite types. /// public required bool LoadTableComposites { get; init; } /// /// When false, if the server doesn't support full type loading from the PostgreSQL catalogs, /// support the basic set of types via information hardcoded inside Npgsql. /// public required bool LoadTypes { get; init; } = true; /// /// Load type definitions from the given schemas. /// public required string[]? TypeLoadingSchemas { get; init; } } /// /// Options builder for configuring Npgsql type loading. /// public sealed class NpgsqlTypeLoadingOptionsBuilder { bool _loadTableComposites; bool _loadTypes = true; List? _typeLoadingSchemas; internal NpgsqlTypeLoadingOptionsBuilder() {} /// /// Enable loading table composite type definitions, and not just free-standing composite types. /// public NpgsqlTypeLoadingOptionsBuilder EnableTableCompositesLoading(bool enable = true) { _loadTableComposites = enable; return this; } /// /// Enable loading of types, when disabled Npgsql falls back to a small, builtin, set of known types and type ids. /// public NpgsqlTypeLoadingOptionsBuilder EnableTypeLoading(bool enable = true) { _loadTypes = enable; return this; } /// /// Set the schemas to load types from, this can be used to reduce the work done during type loading. /// /// Npgsql will always load types from the following schemas: pg_catalog, information_schema, pg_toast. /// Any user-defined types (typcategory 'U') will also be loaded regardless of their schema. /// Schemas to load types from. public NpgsqlTypeLoadingOptionsBuilder SetTypeLoadingSchemas(params IEnumerable? schemas) { if (schemas is null) { _typeLoadingSchemas = null; return this; } _typeLoadingSchemas = new(); foreach (var schema in schemas) { if (schema is not { Length: > 0 }) { _typeLoadingSchemas = null; throw new ArgumentException("Schema cannot be null or empty."); } _typeLoadingSchemas.Add(schema); } return this; } internal NpgsqlTypeLoadingOptions Build() => new() { LoadTableComposites = _loadTableComposites, LoadTypes = _loadTypes, TypeLoadingSchemas = _typeLoadingSchemas?.ToArray() }; } /// /// An option specified in the connection string that activates special compatibility features. /// public enum ServerCompatibilityMode { /// /// No special server compatibility mode is active /// None, /// /// The server is an Amazon Redshift instance. /// [Obsolete("ServerCompatibilityMode.Redshift no longer does anything and can be safely removed.")] Redshift, /// /// The server is doesn't support full type loading from the PostgreSQL catalogs, support the basic set /// of types via information hardcoded inside Npgsql. /// NoTypeLoading, }
X Tutup