123456789_123456789_123456789_123456789_123456789_

Class: PG::CopyCoder

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Coder
Instance Chain:
self, Coder
Inherits: PG::Coder
Defined in: ext/pg_copy_coder.c,
ext/pg_copy_coder.c,
lib/pg/coder.rb

Overview

This is the base class for all type cast classes for COPY data,

Constant Summary

Coder - Inherited

FORMAT_ERROR_MASK, FORMAT_ERROR_TO_PARTIAL, FORMAT_ERROR_TO_RAISE, FORMAT_ERROR_TO_STRING, TIMESTAMP_APP_LOCAL, TIMESTAMP_APP_UTC, TIMESTAMP_DB_LOCAL, TIMESTAMP_DB_UTC

Class Method Summary

Coder - Inherited

.new

Create a new coder object based on the attribute Hash.

Instance Attribute Summary

Coder - Inherited

#flags

Get current bitwise OR-ed coder flags.

#flags=

Set coder specific bitwise OR-ed flags.

#format

The format code that is sent alongside with an encoded query parameter value.

#format=

Specifies the format code that is sent alongside with an encoded query parameter value.

#name

Name of the coder or the corresponding data type.

#oid

The type OID that is sent alongside with an encoded query parameter value.

#oid=

Specifies the type OID that is sent alongside with an encoded query parameter value.

Instance Method Summary

Coder - Inherited

#==, #dup, #inspect, #inspect_short, #marshal_dump, #marshal_load,
#to_h

Returns coder attributes as Hash.

Constructor Details

This class inherits a constructor from PG::Coder

Instance Attribute Details

#delimiterString (rw)

The character that separates columns within each row (line) of the file.

[ GitHub ]

  
# File 'ext/pg_copy_coder.c', line 113

static VALUE
pg_copycoder_delimiter_get(VALUE self)
{
	t_pg_copycoder *this = RTYPEDDATA_DATA(self);
	return rb_str_new(&this->delimiter, 1);
}

#delimiter=(String) (rw)

Specifies the character that separates columns within each row (line) of the file. The default is a tab character in text format. This must be a single one-byte character.

This option is ignored when using binary format.

[ GitHub ]

  
# File 'ext/pg_copy_coder.c', line 95

static VALUE
pg_copycoder_delimiter_set(VALUE self, VALUE delimiter)
{
	t_pg_copycoder *this = RTYPEDDATA_DATA(self);
	rb_check_frozen(self);
	StringValue(delimiter);
	if(RSTRING_LEN(delimiter) != 1)
		rb_raise( rb_eArgError, "delimiter size must be one byte");
	this->delimiter = *RSTRING_PTR(delimiter);
	return delimiter;
}

#null_string (rw)

The string that represents a null value.

[ GitHub ]

  
# File 'ext/pg_copy_coder.c', line 140

static VALUE
pg_copycoder_null_string_get(VALUE self)
{
	t_pg_copycoder *this = RTYPEDDATA_DATA(self);
	return this->null_string;
}

#null_string=(null_string) (rw)

Specifies the string that represents a null value. The default is \N (backslash-N) in text format. You might prefer an empty string even in text format for cases where you don’t want to distinguish nulls from empty strings.

This option is ignored when using binary format.

[ GitHub ]

  
# File 'ext/pg_copy_coder.c', line 127

static VALUE
pg_copycoder_null_string_set(VALUE self, VALUE null_string)
{
	t_pg_copycoder *this = RTYPEDDATA_DATA(self);
	rb_check_frozen(self);
	StringValue(null_string);
	RB_OBJ_WRITE(self, &this->null_string, null_string);
	return null_string;
}

#type_mapPG::TypeMap (rw)

The TypeMap that will be used for encoding and decoding of columns.

[ GitHub ]

  
# File 'ext/pg_copy_coder.c', line 179

static VALUE
pg_copycoder_type_map_get(VALUE self)
{
	t_pg_copycoder *this = RTYPEDDATA_DATA( self );

	return this->typemap;
}

#type_map=(map) (rw)

Defines how single columns are encoded or decoded. map must be a kind of TypeMap .

Defaults to a TypeMapAllStrings , so that TextEncoder::String respectively TextDecoder::String is used for encoding/decoding of each column.

[ GitHub ]

  
# File 'ext/pg_copy_coder.c', line 158

static VALUE
pg_copycoder_type_map_set(VALUE self, VALUE type_map)
{
	t_pg_copycoder *this = RTYPEDDATA_DATA( self );

	rb_check_frozen(self);
	if ( !rb_obj_is_kind_of(type_map, rb_cTypeMap) ){
		rb_raise( rb_eTypeError, "wrong elements type %s (expected some kind of PG::TypeMap)",
				rb_obj_classname( type_map ) );
	}
	RB_OBJ_WRITE(self, &this->typemap, type_map);

	return type_map;
}

Instance Method Details

#to_h

[ GitHub ]

  
# File 'lib/pg/coder.rb', line 90

def to_h
	{ **super,
		type_map: type_map,
		delimiter: delimiter,
		null_string: null_string,
	}
end