Documentation

Overview

    Package ntcsv provides a convenient access to CSV files as n-tuple data.

    Examples:

    nt, err := ntcsv.Open("testdata/simple.csv")
    if err != nil {
        log.Fatal(err)
    }
    defer nt.DB().Close()
    

    or, with a different configuration for the comma/comment runes:

    nt, err := ntcsv.Open("testdata/simple.csv", ntcsv.Comma(' '), ntcsv.Comment('#'))
    if err != nil {
        log.Fatal(err)
    }
    defer nt.DB().Close()
    

    Give our own names to the CSV columns (default: "var1", "var2", ...):

    nt, err := ntcsv.Open("testdata/simple.csv", ntcsv.Columns("var1", "i64", "foo"))
    

    Take the names from the CSV header (note that the header *must* exist):

    nt, err := ntcsv.Open("testdata/simple-with-header.csv", ntcsv.Header())
    

    Override the names from the CSV header with our own:

    nt, err := ntcsv.Open("testdata/simple-with-header.csv", ntcsv.Header(), ntcsv.Columns("v1", "v2", "v3")
    

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func Open

    func Open(name string, opts ...Option) (*ntup.Ntuple, error)

      Open opens a CSV file in read-only mode and returns a n-tuple connected to that.

      Example
      Output:
      
      0 0.000000 "str-0"
      1 1.000000 "str-1"
      2 2.000000 "str-2"
      3 3.000000 "str-3"
      4 4.000000 "str-4"
      5 5.000000 "str-5"
      6 6.000000 "str-6"
      7 7.000000 "str-7"
      8 8.000000 "str-8"
      9 9.000000 "str-9"
      
      Example (FromRemote)
      Output:
      
      0 0.000000 "str-0"
      1 1.000000 "str-1"
      2 2.000000 "str-2"
      3 3.000000 "str-3"
      4 4.000000 "str-4"
      5 5.000000 "str-5"
      6 6.000000 "str-6"
      7 7.000000 "str-7"
      8 8.000000 "str-8"
      9 9.000000 "str-9"
      
      Example (WithDefaultVarNames)
      Output:
      
      0 0.000000 "str-0"
      1 1.000000 "str-1"
      2 2.000000 "str-2"
      3 3.000000 "str-3"
      4 4.000000 "str-4"
      5 5.000000 "str-5"
      6 6.000000 "str-6"
      7 7.000000 "str-7"
      8 8.000000 "str-8"
      9 9.000000 "str-9"
      
      Example (WithHeader)
      Output:
      
      0 0.000000 "str-0"
      1 1.000000 "str-1"
      2 2.000000 "str-2"
      3 3.000000 "str-3"
      4 4.000000 "str-4"
      5 5.000000 "str-5"
      6 6.000000 "str-6"
      7 7.000000 "str-7"
      8 8.000000 "str-8"
      9 9.000000 "str-9"
      
      Example (WithHeaderAndExlicitColumns)
      Output:
      
      0 0.000000 "str-0"
      1 1.000000 "str-1"
      2 2.000000 "str-2"
      3 3.000000 "str-3"
      4 4.000000 "str-4"
      5 5.000000 "str-5"
      6 6.000000 "str-6"
      7 7.000000 "str-7"
      8 8.000000 "str-8"
      9 9.000000 "str-9"
      
      Example (WithHeaderAndImplicitColumns)
      Output:
      
      0 0.000000 "str-0"
      1 1.000000 "str-1"
      2 2.000000 "str-2"
      3 3.000000 "str-3"
      4 4.000000 "str-4"
      5 5.000000 "str-5"
      6 6.000000 "str-6"
      7 7.000000 "str-7"
      8 8.000000 "str-8"
      9 9.000000 "str-9"
      

      Types

      type Option

      type Option func(c *csvdriver.Conn)

        Option configures the underlying sql.DB connection to the n-tuple.

        func Columns

        func Columns(names ...string) Option

          Columns names the n-tuple columns with the given slice.

          func Comma

          func Comma(v rune) Option

            Comma configures the n-tuple to use v as the comma delimiter between columns.

            func Comment

            func Comment(v rune) Option

              Comment configures the n-tuple to use v as the comment character for start of line.

              func Header() Option

                Header informs the n-tuple the CSV file has a header line.

                Source Files