コード例 #1
0
 /// <summary>
 /// Constructs an instance of the <see cref="NpgsqlRangeTypeMapping"/> class.
 /// </summary>
 /// <param name="storeType">The database type to map</param>
 /// <param name="clrType">The CLR type to map.</param>
 /// <param name="rangeMapping">The type mapping of the ranges contained in this multirange.</param>
 /// <param name="sqlGenerationHelper">The SQL generation helper to delimit the store name.</param>
 public NpgsqlMultirangeTypeMapping(
     string storeType,
     Type clrType,
     NpgsqlRangeTypeMapping rangeMapping,
     ISqlGenerationHelper sqlGenerationHelper)
     : this(storeType, storeTypeSchema : null, clrType, rangeMapping, sqlGenerationHelper)
 {
 }
コード例 #2
0
 protected NpgsqlMultirangeTypeMapping(
     RelationalTypeMappingParameters parameters,
     NpgsqlDbType npgsqlDbType,
     NpgsqlRangeTypeMapping rangeMapping,
     ISqlGenerationHelper sqlGenerationHelper)
     : base(parameters, npgsqlDbType)
 {
     RangeMapping         = rangeMapping;
     SubtypeMapping       = rangeMapping.SubtypeMapping;
     _sqlGenerationHelper = sqlGenerationHelper;
 }
コード例 #3
0
 /// <summary>
 /// Constructs an instance of the <see cref="NpgsqlRangeTypeMapping"/> class.
 /// </summary>
 /// <param name="storeType">The database type to map</param>
 /// <param name="storeTypeSchema">The schema of the type.</param>
 /// <param name="clrType">The CLR type to map.</param>
 /// <param name="rangeMapping">The type mapping of the ranges contained in this multirange.</param>
 /// <param name="sqlGenerationHelper">The SQL generation helper to delimit the store name.</param>
 public NpgsqlMultirangeTypeMapping(
     string storeType,
     string?storeTypeSchema,
     Type clrType,
     NpgsqlRangeTypeMapping rangeMapping,
     ISqlGenerationHelper sqlGenerationHelper)
     : base(
         sqlGenerationHelper.DelimitIdentifier(storeType, storeTypeSchema), clrType,
         GenerateNpgsqlDbType(rangeMapping.SubtypeMapping))
 {
     RangeMapping         = rangeMapping;
     SubtypeMapping       = rangeMapping.SubtypeMapping;
     _sqlGenerationHelper = sqlGenerationHelper;
 }
コード例 #4
0
 public NodaTimePlugin()
 {
     _timestampLocalDateTimeRange = new NpgsqlRangeTypeMapping <LocalDateTime>(
         "tsrange", typeof(NpgsqlRange <LocalDateTime>), _timestampLocalDateTime, NpgsqlDbType.Range | NpgsqlDbType.Timestamp);
     _timestampInstantRange = new NpgsqlRangeTypeMapping <Instant>(
         "tsrange", typeof(NpgsqlRange <Instant>), _timestampInstant, NpgsqlDbType.Range | NpgsqlDbType.Timestamp);
     _timestamptzInstantRange = new NpgsqlRangeTypeMapping <Instant>(
         "tstzrange", typeof(NpgsqlRange <Instant>), _timestamptzInstant, NpgsqlDbType.Range | NpgsqlDbType.TimestampTz);
     _timestamptzZonedDateTimeRange = new NpgsqlRangeTypeMapping <ZonedDateTime>(
         "tstzrange", typeof(NpgsqlRange <ZonedDateTime>), _timestamptzZonedDateTime, NpgsqlDbType.Range | NpgsqlDbType.TimestampTz);
     _timestamptzOffsetDateTimeRange = new NpgsqlRangeTypeMapping <OffsetDateTime>(
         "tstzrange", typeof(NpgsqlRange <OffsetDateTime>), _timestamptzOffsetDateTime, NpgsqlDbType.Range | NpgsqlDbType.TimestampTz);
     _dateRange = new NpgsqlRangeTypeMapping <LocalDate>(
         "daterange", typeof(NpgsqlRange <LocalDate>), _date, NpgsqlDbType.Range | NpgsqlDbType.Date);;
 }
コード例 #5
0
        /// <summary>
        /// Constructs an instance of the <see cref="NpgsqlNodaTimeTypeMappingSourcePlugin"/> class.
        /// </summary>
        public NpgsqlNodaTimeTypeMappingSourcePlugin([NotNull] ISqlGenerationHelper sqlGenerationHelper)
        {
            _timestampLocalDateTimeRange    = new NpgsqlRangeTypeMapping("tsrange", typeof(NpgsqlRange <LocalDateTime>), _timestampLocalDateTime, sqlGenerationHelper);
            _timestampInstantRange          = new NpgsqlRangeTypeMapping("tsrange", typeof(NpgsqlRange <Instant>), _timestampInstant, sqlGenerationHelper);
            _timestamptzInstantRange        = new NpgsqlRangeTypeMapping("tstzrange", typeof(NpgsqlRange <Instant>), _timestamptzInstant, sqlGenerationHelper);
            _timestamptzZonedDateTimeRange  = new NpgsqlRangeTypeMapping("tstzrange", typeof(NpgsqlRange <ZonedDateTime>), _timestamptzZonedDateTime, sqlGenerationHelper);
            _timestamptzOffsetDateTimeRange = new NpgsqlRangeTypeMapping("tstzrange", typeof(NpgsqlRange <OffsetDateTime>), _timestamptzOffsetDateTime, sqlGenerationHelper);
            _dateRange = new NpgsqlRangeTypeMapping("daterange", typeof(NpgsqlRange <LocalDate>), _date, sqlGenerationHelper);

            var storeTypeMappings = new Dictionary <string, RelationalTypeMapping[]>(StringComparer.OrdinalIgnoreCase)
            {
                { "timestamp", new RelationalTypeMapping[] { _timestampInstant, _timestampLocalDateTime } },
                { "timestamp without time zone", new RelationalTypeMapping[] { _timestampInstant, _timestampLocalDateTime } },
                { "timestamptz", new RelationalTypeMapping[] { _timestamptzInstant, _timestamptzZonedDateTime, _timestamptzOffsetDateTime } },
                { "timestamp with time zone", new RelationalTypeMapping[] { _timestamptzInstant, _timestamptzZonedDateTime, _timestamptzOffsetDateTime } },
                { "date", new RelationalTypeMapping[] { _date } },
                { "time", new RelationalTypeMapping[] { _time } },
                { "time without time zone", new RelationalTypeMapping[] { _time } },
                { "timetz", new RelationalTypeMapping[] { _timetz } },
                { "time with time zone", new RelationalTypeMapping[] { _timetz } },
                { "interval", new RelationalTypeMapping[] { _period } },

                { "tsrange", new RelationalTypeMapping[] { _timestampInstantRange, _timestampLocalDateTimeRange } },
                { "tstzrange", new RelationalTypeMapping[] { _timestamptzInstantRange, _timestamptzZonedDateTimeRange, _timestamptzOffsetDateTimeRange } },
                { "daterange", new RelationalTypeMapping[] { _dateRange } }
            };

            var clrTypeMappings = new Dictionary <Type, RelationalTypeMapping>
            {
                { typeof(Instant), _timestampInstant },
                { typeof(LocalDateTime), _timestampLocalDateTime },
                { typeof(ZonedDateTime), _timestamptzZonedDateTime },
                { typeof(OffsetDateTime), _timestamptzOffsetDateTime },
                { typeof(LocalDate), _date },
                { typeof(LocalTime), _time },
                { typeof(OffsetTime), _timetz },
                { typeof(Period), _period },

                { typeof(NpgsqlRange <Instant>), _timestampInstantRange },
                { typeof(NpgsqlRange <LocalDateTime>), _timestampLocalDateTimeRange },
                { typeof(NpgsqlRange <ZonedDateTime>), _timestamptzZonedDateTimeRange },
                { typeof(NpgsqlRange <LocalDate>), _dateRange },
                { typeof(NpgsqlRange <OffsetDateTime>), _timestamptzOffsetDateTimeRange }
            };

            StoreTypeMappings = new ConcurrentDictionary <string, RelationalTypeMapping[]>(storeTypeMappings, StringComparer.OrdinalIgnoreCase);
            ClrTypeMappings   = new ConcurrentDictionary <Type, RelationalTypeMapping>(clrTypeMappings);
        }
コード例 #6
0
        public NpgsqlTypeMappingSource([NotNull] TypeMappingSourceDependencies dependencies,
                                       [NotNull] RelationalTypeMappingSourceDependencies relationalDependencies,
                                       [NotNull] ISqlGenerationHelper sqlGenerationHelper,
                                       [CanBeNull] INpgsqlOptions npgsqlOptions = null)
            : base(dependencies, relationalDependencies)
        {
            _sqlGenerationHelper = Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));

            // Initialize some mappings which depend on other mappings
            _int4range = new NpgsqlRangeTypeMapping("int4range", typeof(NpgsqlRange <int>), _int4, sqlGenerationHelper);
            _int8range = new NpgsqlRangeTypeMapping("int8range", typeof(NpgsqlRange <long>), _int8, sqlGenerationHelper);
            _numrange  = new NpgsqlRangeTypeMapping("numrange", typeof(NpgsqlRange <decimal>), _numeric, sqlGenerationHelper);
            _tsrange   = new NpgsqlRangeTypeMapping("tsrange", typeof(NpgsqlRange <DateTime>), _timestamp, sqlGenerationHelper);
            _tstzrange = new NpgsqlRangeTypeMapping("tstzrange", typeof(NpgsqlRange <DateTime>), _timestamptz, sqlGenerationHelper);
            _daterange = new NpgsqlRangeTypeMapping("daterange", typeof(NpgsqlRange <DateTime>), _timestamptz, sqlGenerationHelper);

            // Note that PostgreSQL has aliases to some built-in type name aliases (e.g. int4 for integer),
            // these are mapped as well.
            // https://www.postgresql.org/docs/current/static/datatype.html#DATATYPE-TABLE
            var storeTypeMappings = new Dictionary <string, RelationalTypeMapping[]>(StringComparer.OrdinalIgnoreCase)
            {
                { "boolean", new[] { _bool } },
                { "bool", new[] { _bool } },
                { "bytea", new[] { _bytea } },
                { "real", new[] { _float4 } },
                { "float4", new[] { _float4 } },
                { "double precision", new[] { _float8 } },
                { "float8", new[] { _float8 } },
                { "numeric", new[] { _numeric } },
                { "decimal", new[] { _numeric } },
                { "money", new[] { _money } },
                { "uuid", new[] { _uuid } },
                { "smallint", new RelationalTypeMapping[] { _int2, _int2Byte } },
                { "int2", new RelationalTypeMapping[] { _int2, _int2Byte } },
                { "integer", new[] { _int4 } },
                { "int", new[] { _int4 } },
                { "int4", new[] { _int4 } },
                { "bigint", new[] { _int8 } },
                { "int8", new[] { _int8 } },
                { "text", new[] { _text } },
                { "jsonb", new RelationalTypeMapping[] { _jsonbString, _jsonbDocument, _jsonbElement } },
                { "json", new RelationalTypeMapping[] { _jsonString, _jsonDocument, _jsonElement } },
                { "xml", new[] { _xml } },
                { "citext", new[] { _citext } },
                { "character varying", new[] { _varchar } },
                { "varchar", new[] { _varchar } },
                { "character", new[] { _char } },
                { "char", new[] { _char } },
                { "char(1)", new RelationalTypeMapping[] { _singleChar, _stringAsSingleChar } },
                { "character(1)", new RelationalTypeMapping[] { _singleChar, _stringAsSingleChar } },
                { "date", new[] { _date } },
                { "timestamp without time zone", new[] { _timestamp } },
                { "timestamp", new[] { _timestamp } },
                { "timestamp with time zone", new[] { _timestamptz, _timestamptzDto } },
                { "timestamptz", new[] { _timestamptz, _timestamptzDto } },
                { "interval", new[] { _interval } },
                { "time without time zone", new[] { _time } },
                { "time", new[] { _time } },
                { "time with time zone", new[] { _timetz } },
                { "timetz", new[] { _timetz } },
                { "macaddr", new[] { _macaddr } },
                { "macaddr8", new[] { _macaddr8 } },
                { "inet", new[] { _inet } },
                { "cidr", new[] { _cidr } },
                { "bit", new[] { _bit } },
                { "bit varying", new[] { _varbit } },
                { "varbit", new[] { _varbit } },
                { "hstore", new[] { _hstore } },
                { "point", new[] { _point } },
                { "box", new[] { _box } },
                { "line", new[] { _line } },
                { "lseg", new[] { _lseg } },
                { "path", new[] { _path } },
                { "polygon", new[] { _polygon } },
                { "circle", new[] { _circle } },
                { "xid", new[] { _xid } },
                { "oid", new[] { _oid } },
                { "cid", new[] { _cid } },
                { "regtype", new[] { _regtype } },
                { "lo", new[] { _lo } },
                { "tid", new[] { _tid } },

                { "int4range", new[] { _int4range } },
                { "int8range", new[] { _int8range } },
                { "numrange", new[] { _numrange } },
                { "tsrange", new[] { _tsrange } },
                { "tstzrange", new[] { _tstzrange } },
                { "daterange", new[] { _daterange } },

                { "tsquery", new[] { _tsquery } },
                { "tsvector", new[] { _tsvector } },
                { "regconfig", new[] { _regconfig } }
            };

            var clrTypeMappings = new Dictionary <Type, RelationalTypeMapping>
            {
                { typeof(bool), _bool },