pocketexport

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 22 Imported by: 0

README

pocketexport

The PocketExport plugin is a Go-based plugin for PocketBase. This plugin enables the creation and management of export requests within PocketBase. It provides functionality to store and retrieve information related to export requests, such as filters, sorting preferences, target collection, and file format.

usage

register
package main

import (
  "log"

  _ "github.com/TcMits/pocketexport/migrations"
  "github.com/TcMits/pocketexport"
  "github.com/pocketbase/pocketbase"
)

func main() {
  app := pocketbase.New()

  // register pocketexport app
  if err := pocketexport.Register(app); err != nil {
    log.Fatal(err)
  }

  if err := app.Start(); err != nil {
    log.Fatal(err)
  }
}
apis

to create an export

import PocketBase from 'pocketbase';

const pb = new PocketBase('http://0.0.0.0:8090');

// example create data
const data = {
    "exportCollectionName": "users", // export 'users' collection
    "headers": [
        {
            "fieldName": "name",
            "header": "Tên"
        },
        {
            "fieldName": "updated",
            "header": "Ngày cập nhật",
            "timezone": "Asia/Ho_Chi_Minh"
        },
        {
            "fieldName": "gender",
            "header": "Lựa chọn",
            "valueMap": {
                "male": "Nam",
                "female": "Nữ"
            }
        }
    ],
    "filter": "name != \"\"",
    "sort": "name",
    "format": "csv",
    "ownerId": "4gw3vii9aopnnvc",
    "ownerCollectionName": "" // empty str means that you are admin
};

const record = await pb.collection('pocketexport_exports').create(data);

Documentation

Index

Constants

View Source
const (
	// FormatCSV is the csv format
	FormatCSV = "csv"
	// FormatXLSX is the xlsx format
	FormatXLSX = "xlsx"
)
View Source
const (
	// ExportCollectionField is the field name for the export collection
	PocketExportCollectionName = "pocketexport_exports"
	// ExportCollectionNameField is the field name for the export collection
	ExportCollectionNameField = "exportCollectionName"
	// OwnerIdField is the field name for the owner id
	OwnerIdField = "ownerId"
	// OwnerCollectionNameField is the field name for the owner collection name
	OwnerCollectionNameField = "ownerCollectionName"
	// FilterField is the field name for the export filter
	FilterField = "filter"
	// SortField is the field name for the export sort
	SortField = "sort"
	// HeadersField is the field name for the export headers
	HeadersField = "headers"
	// FormatField is the field name for the export format
	FormatField = "format"
	// OutputField is the field name for the export output
	OutputField = "output"
)

Variables

View Source
var (
	ErrIsNotExport = validation.NewError("validation_is_not_export", "is not export")
)

Functions

func Register

func Register(app core.App, opts ...RegisterOption) error

Register registers the pocketexport app with the core.App

Types

type Export

type Export struct {
	*models.Record
	// contains filtered or unexported fields
}

Export represents an export

func NewExport

func NewExport(r *models.Record) *Export

NewExport creates a new export

func (*Export) Admin

func (e *Export) Admin() *models.Admin

Admin return the admin, can be null

func (*Export) AuthRecord

func (e *Export) AuthRecord() *models.Record

AuthRecord return the auth record, can be null

func (*Export) ExportCollection

func (e *Export) ExportCollection() *models.Collection

ExportCollection return the export collection

func (*Export) Fill

func (e *Export) Fill(dao *daos.Dao) (err error)

Fill fills the export with the export collection, auth record and admin

func (*Export) Headers

func (e *Export) Headers() []HeaderItem

Headers return the headers

type HeaderItem

type HeaderItem struct {
	FieldName string         `json:"fieldName"`
	Header    string         `json:"header"`
	Timezone  string         `json:"timezone"`
	ValueMap  map[string]any `json:"valueMap"`
}

func (*HeaderItem) Format

func (i *HeaderItem) Format(value any) any

Format formats the value.

type IPocketExport

type IPocketExport interface {
	// ValidateAndFill validates the record and fills the export
	// this function should be called after using form validation because
	// it does not fully validate the record
	ValidateAndFill(*models.Record) (*Export, error)
	// GenerateExportOutput generates the output for the export
	GenerateExportOutput(io.Writer, *Export) error
}

type PocketExport

type PocketExport struct {
	// contains filtered or unexported fields
}

func New

func New(app core.App) *PocketExport

New creates a new pocketexport

func (*PocketExport) GenerateExportOutput

func (p *PocketExport) GenerateExportOutput(dst io.Writer, r *Export) error

GenerateExportOutput implement PocketExport interface

func (*PocketExport) Register

func (p *PocketExport) Register(opts ...RegisterOption) error

Register implement PocketExport interface

func (*PocketExport) ValidateAndFill

func (p *PocketExport) ValidateAndFill(r *models.Record) (*Export, error)

ValidateRecord implement PocketExport interface

type RegisterOption

type RegisterOption func(*registerConfig)

func AutoDelete

func AutoDelete(d bool) RegisterOption

AutoDelete sets the autoDelete option if d is true, the export will be deleted automatically after create new export

func AutoDeleteDuration

func AutoDeleteDuration(d time.Duration) RegisterOption

AutoDeleteDuration sets the autoDeleteDuration option

func GenerateInBackground

func GenerateInBackground(g bool) RegisterOption

GenerateInBackground sets the generateOutputInBackground option if g is true, the export output will be generated in background

Directories

Path Synopsis
cmd
run

Jump to

Keyboard shortcuts

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