GithubHelp home page GithubHelp logo

gompact / gofixtures Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 0.0 226 KB

Golang lib/command line tool to load fixtures to databases, useful for testing

Go 95.05% Shell 3.65% Dockerfile 1.30%
go golang fixtures postgresql yaml json test-automation test-data fixture-loading csv database

gofixtures's Introduction

gofixtures

version: 3.0.0

Build Status

A small command line tool written in Go lang, that loads fixtures and insert it's records to a database. Currently supports YAML and JSON files through CLI, and supports PostgreSQL only.

Supported File Types

  • JSON
  • YAML
  • CSV

Supported Databases

  • PostgreSQL
  • MySQL
  • SQLServer
  • MongoDB
  • Redis
  • Cassandra
  • Firebase

Install

This will install gofixtures to your $GOPATH/bin

$ go get github.com/schehata/gofixtures/v3

Usage

To start using gofixtures you need to have a configuration file, that includes information on which db driver should it use, and what are the credentials It could be written in YAML or JSON, here is an example for .gofixtures.yaml which will be automatically loaded by gofixtures:

import (
    "github.com/schehata/gofixutres/v3"
    "github.com/schehata/gofixutres/v3/entity"
)

func main() {
    config := entity.Config {
      entity.DBConfig{
        Driver: "postgres"
      }
    }
    gf, err := gofixutres.New(config)
    if err != nil {
      log.Fatal(err)
    }
    err = gf.LoadFromFiles(string[]{"./fixtures/countries.yml"})
    if err != nil {
      log.Fatal(err)
    }
}

example of ./fixtures/countries.yml:

table: countries
records:
  - name: Egypt
  - capital: Cairo
  - name: Germany
    capital: Berlin
  - name: Netherlands
    capital: Amsterdam
  1. the previous yaml file inserts three records into table countries
  2. gofixtures will parse each record and insert it into the database

Notes on CSV Support

  • Column names are read from the first row
  • Filename will be used as a tablename
  • For now only comma ',' is allowed as a separator, will work on providing CLI flags to change that as needed

Usage from Command Line

You can use the gofixtures CLI tool to quickly load data into datastores from the command line, check the CLI docs.

gofixtures's People

Contributors

ishehata avatar islamshehatafriday avatar schehata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gofixtures's Issues

Add Support for csv

Add a new parser that allows reading from CSV files and feed its data to the database.

Create global configuration file Instead of db configuration only

change the db configuration file to be more flexible and be be able to include different configuration types. for example configurations could be added for the CSV parser.

the yaml or json file could be a map with keys of a type name, for example

db:
   user: ....
csv:
   separator: ...

Add new function to clear database tables

This could be very useful for testing, as gofixutres could be used as a library to setup testing data and then clear the database at the end of each test. in order to do that a clear function is needed, as a library function and as a cli command.

For that purpose the CLI should have commands instead of just assuming loading data each time, so these commands could be

  • load : which loads data from files
  • clear : which clears database
  • version: which shows current version of the gofixtures cli

Create sql tables if they doesn't exist using cli flag

Currently gofixtures will fail to insert data if the targeted table doesn't exit.

Solution:

  • add a cli flag that allows the user to enforce creation of the table if it doesn't exist
  • would it be possible to guess the type of column from the data ?

Details:

  • Create cli flag called "autoTables" which takes a boolean value, true or false
  • if its true, check if table exists, if not create it.

Improve the CLI logs appearance, and use prefixes

  • Add Prefix for different CLI log types, specially that in the future there will be debug messages.
  • Use Colord outputs for different logging types

e.g:

[Warning]: some warning
[Info]: info messages
[Error]: ...

Fake Mode, Ability to just print sql statement without real insert to the db

  • Allow users to call gofixtures and print sql statements of data read from the file without really inserting anything to a db.

this could be useful for someone, although i am not sure if there is a real case for this.

  • maybe just create a new fake Postgres DAL, which is just a struct that implements the datastore interface and does nothing but printing the sql statements.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.