Record

info.fingo.spata.Record
See theRecord companion class
object Record

Record helper object. Used to create and convert records.

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Record.type

Members list

Type members

Classlikes

final class Builder

Helper to incrementally build records from typed values. Supports also values removal.

Helper to incrementally build records from typed values. Supports also values removal.

Value parameters

buf

buffer used to incrementally build record's content.

removed

keys of fields to be removed from record

Attributes

Supertypes
class Object
trait Matchable
class Any
object ProductOps extends ProductOps

Given instance to easily bring ProductOps extension in scope.

Given instance to easily bring ProductOps extension in scope.

Attributes

Companion
trait
Supertypes
trait ProductOps
class Object
trait Matchable
class Any
Self type
ProductOps.type
trait ProductOps

Extension of scala.Product to provide convenient conversion to records.

Extension of scala.Product to provide convenient conversion to records.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object ProductOps.type

Value members

Concrete methods

def apply(values: String*)(header: Header): Record

Creates record.

Creates record.

The size of header has to match the number of values. In the rare case when it does not, the header is shrunk or extended accordingly. While extending, the new values are added in tuple-style, with values matching their position (e.g. extending Header("X","Y","Z") by 1 yields Header("X","Y","Z","_4"))

Value parameters

header

record header - keys for values (field names)

values

the values forming the record

Attributes

Returns

new record

Creates new record builder.

Creates new record builder.

Attributes

def from[P <: Product : FromProduct](product: P): Record

Creates a record from scala.Product, e.g. case class.

Creates a record from scala.Product, e.g. case class.

This renders product (class) values to string representation. In contrast to simple toString operation, this process allows more control over output format, e.g. taking into account locale or render simple value from scala.Option.

case class Person(name: String, born: LocalDate, died: Option[LocalDate])
val person: Person = Person("Nicolaus Copernicus", LocalDate.of(1473,2,19), Some(LocalDate.of(1543,5,24)))
val record: Record = Record.from(person)

Please note, that the conversion is name-based (case class field names are used to form record header) and is case sensitive.

It is possible to use a tuple instead of case class, using tuple-optimized from method.

Current implementation supports only shallow conversion - each product field has to be rendered to single record field through StringRenderer.

Because conversion from product requires rendering of all fields through StringRenderer, there is no way to provide custom formatter. If other then the default formatting has to be used, a custom given instance of stringRenderer has to be provided:

case class Person(name: String, born: LocalDate, died: Option[LocalDate])
val person: Person = Person("Nicolaus Copernicus", LocalDate.of(1473,2,19), Some(LocalDate.of(1543,5,24)))
given ldsr: StringRenderer[LocalDate] with
 def apply(date: LocalDate) = DateTimeFormatter.ofPattern("dd.MM.yyyy").format(date)
val record: Record = Record.from(person)

Type parameters

P

the scala.Product type to create new record from with given type class providing support for conversion (arranged internally by spata, assuming StringRenderer is available for all product field types)

Value parameters

product

the product to convert (render) to record

Attributes

Returns

new record

def from[T <: Tuple : FromTuple](tuple: T): Record

Creates a record from scala.Tuple. Althogh conversion from product works for tuples too, this tuple-optimized version is more efficient.

Creates a record from scala.Tuple. Althogh conversion from product works for tuples too, this tuple-optimized version is more efficient.

This renders tuple values to string representation. In contrast to simple toString operation, this process allows more control over output format, e.g. taking into account locale or render simple value from scala.Option.

type T3 = (String, LocalDate, Option[LocalDate])
val tuple: T3 = ("Nicolaus Copernicus", LocalDate.of(1473,2,19), Some(LocalDate.of(1543,5,24)))
val record: Record = Record.from(tuple)

Please note, that the conversion is index-based and the header will be created from tuple field naming convention: _1, _2 etc.

Current implementation supports only shallow conversion - each tuple field has to be rendered to single record field through StringRenderer.

Because conversion from tuple requires rendering of all fields through StringRenderer, there is no way to provide custom formatter. If other then the default formatting has to be used, a custom given instance of stringRenderer has to be provided:

type T3 = (String, LocalDate, Option[LocalDate])
val tuple: T3 = ("Nicolaus Copernicus", LocalDate.of(1473,2,19), Some(LocalDate.of(1543,5,24)))
given ldsr: StringRenderer[LocalDate] with
 def apply(date: LocalDate) = DateTimeFormatter.ofPattern("dd.MM.yyyy").format(date)
val record: Record = Record.from(tuple)

Type parameters

T

the scala.Tuple type to create new record from with given type class providing support for conversion (arranged internally by spata, assuming StringRenderer is available for all tuple field types)

Value parameters

tuple

the tuple to convert (render) to record

Attributes

Returns

new record

def fromPairs(keysValues: (String, String)*): Record

Creates record from key-value pairs. Keys are extracted as header.

Creates record from key-value pairs. Keys are extracted as header.

This method does not enforce unique keys (as it is not enforced by header constructor). Providing duplicates does not cause any erroneous conditions while accessing record data, however the values associated with second and next duplicated keys will be accessible only by index.

Value parameters

keysValues

list of keys (names) and values forming record

Attributes

Returns

new record

def fromValues(values: String*): Record

Creates record from list of values. Record header is created in tuple-like form: _1, _2, _3 etc. Header creation is lazy - records created in this way may be effectively headerless, if values are accessed by index only.

Creates record from list of values. Record header is created in tuple-like form: _1, _2, _3 etc. Header creation is lazy - records created in this way may be effectively headerless, if values are accessed by index only.

Value parameters

values

list of values forming record

Attributes

Returns

new record

Givens

Givens

given ProductOps: ProductOps.type

Given instance to easily bring ProductOps extension in scope.

Given instance to easily bring ProductOps extension in scope.

Attributes

Given instance to convert record builder to record.

Given instance to convert record builder to record.

Attributes