Skip to content

Commit

Permalink
Remove the jsonobj import
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmartinelli committed Jun 3, 2018
1 parent 2788fc8 commit e248fcb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 63 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,6 @@ This works the same for invalid JSON objects.
pgfutter csv --table violations traffic_violations.csv
```

### Import single JSON object

Instead of using JSON lines you can also [import a single JSON object](https://github.com/lukasmartinelli/pgfutter/issues/9)
into the database. This will load the JSON document into memory first.

```bash
pgfutter jsonobj document.json
```

## Alternatives

For more sophisticated needs you should take a look at [pgloader](http://pgloader.io).
Expand Down
37 changes: 0 additions & 37 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -67,42 +66,6 @@ func copyJSONRows(i *Import, reader *bufio.Reader, ignoreErrors bool) (error, in
return nil, success, failed
}

func importJSONObject(filename string, connStr string, schema string, tableName string, dataType string) error {
db, err := connect(connStr, schema)
if err != nil {
return err
}
defer db.Close()

// The entire file is read into memory because we need to add
// it into the PostgreSQL transaction, this will hit memory limits
// for big JSON objects
var bytes []byte
if filename == "" {
bytes, err = ioutil.ReadAll(os.Stdin)
} else {
bytes, err = ioutil.ReadFile(filename)
}
if err != nil {
return err
}

i, err := NewJSONImport(db, schema, tableName, "data", dataType)
if err != nil {
return err
}

// The JSON file is not validated at client side
// it is just copied into the database
// If the JSON file is corrupt PostgreSQL will complain when querying
err = i.AddRow(string(bytes))
if err != nil {
return err
}

return i.Commit()
}

func importJSON(filename string, connStr string, schema string, tableName string, ignoreErrors bool, dataType string) error {

db, err := connect(connStr, schema)
Expand Down
17 changes: 0 additions & 17 deletions pgfutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,6 @@ func main() {
return err
},
},
{
Name: "jsonobj",
Usage: "Import single JSON object into database",
Action: func(c *cli.Context) error {
cli.CommandHelpTemplate = strings.Replace(cli.CommandHelpTemplate, "[arguments...]", "<json-file>", -1)

filename := c.Args().First()

schema := c.GlobalString("schema")
tableName := parseTableName(c, filename)
dataType := getDataType(c)

connStr := parseConnStr(c)
err := importJSONObject(filename, connStr, schema, tableName, dataType)
return err
},
},
{
Name: "csv",
Usage: "Import CSV into database",
Expand Down

4 comments on commit e248fcb

@ebbauer
Copy link

@ebbauer ebbauer commented on e248fcb Aug 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove this functionality? it seems pretty useful

@lukasmartinelli
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you can emulate it using bash anyway. e.g. smth like cat mygeojson | jq . -c > mygeojsonperline and then you have a line delimited json file.

@JimFAmazon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I find the unsubscribe link for pgfutter?

@ebbauer
Copy link

@ebbauer ebbauer commented on e248fcb Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.