importExportHelper

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

importExportHelper

importExportHelper contains helpers for importing and exporting data in CSV and JSON formats.

It’s designed to work with the project’s standard file locations (via paths) and logging conventions.

Key functions

  • ExportCSV[T any](exportName string, exportList []T, idField entities.Field) error
  • ExportJSON[T any](exportName string, exportList []T, idField entities.Field) error
  • ImportCSV[T any](importName string, entryTypeToInsert T, importProcessor func(*T) (string, error)) error

Behaviour notes

  • CSV delimiter defaults to FIELDSEPARATOR (currently |).
  • ExportCSV writes to the defaults folder (paths.Defaults()), and appends a generated # ... metadata line at the end of the file.
  • ExportJSON writes one JSON file per record into the dumps folder (paths.Dumps()).
  • Naming uses a KSUID-based prefix (via idHelpers.GetUUID()), and attempts to include the record’s ID field.

Example

import (
    "github.com/mt1976/frantic-core/dao/entities"
    "github.com/mt1976/frantic-core/importExportHelper"
)

type User struct {
    ID   int
    Name string
}

func exportUsers(users []User) error {
    return importExportHelper.ExportCSV("users", users, entities.Field("ID"))
}

func importUsers() error {
    return importExportHelper.ImportCSV("users", User{}, func(u *User) (string, error) {
        // create/update in DB here
        return u.Name, nil
    })
}

Documentation

Overview

Package importExportHelper contains helpers for importing and exporting data in various formats.

Index

Constants

This section is empty.

Variables

View Source
var FIELDSEPARATOR = '|'
View Source
var SEP = "-"

Functions

func ExportCSV

func ExportCSV[T any](exportName string, exportList []T, idField entities.Field) error

func ExportJSON added in v1.5.1

func ExportJSON[T any](exportName string, exportList []T, idField entities.Field) error

func ImportCSV

func ImportCSV[T any](importName string, entryTypeToInsert T, importProcessor func(*T) (string, error)) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL