GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - bartnv/xml-to-postgres: Fast tool to convert XML files with repeating element sets into PostgreSQL COPY format

BranchesTags
Open more actions menu

Latest commit

 

History

114 Commits
114 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/ISSUE_TEMPLATE
.github/ISSUE_TEMPLATE
 
 
src
src
 
 
.gitignore
.gitignore
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

xml-to-postgres

A fast tool to convert XML files with repeating element sets into PostgreSQL dump format.

To use this tool you need to create a simple YAML configuration file that describes how to turn repeating element sets in an XML document into row-based data for importing into PostgreSQL. For efficiency, the data is output in PostgreSQL dump format, suitable for importing with the COPY command. This tool processes one row at a time and does not need to keep the whole XML DOM in memory, so it has a very low memory footprint and can be used to convert datasets larger than the available RAM. The tool can split out further repeating fields into extra tables with a one-to-many relationship (with foreign key) to the main table.

Features

  • XPath-like selection of column values
  • Very low runtime memory requirements
  • Read column values from XML attributes
  • Apply search-and-replace on values
  • Filter the output with regex
  • Write extra tables with a foreign key to the main table
  • Operate in a pipeline to avoid on-disk intermediary steps

Compiling

This project uses the Rust 2021 Edition, which means you need at a minimum to have the Rust 1.56 toolchain installed. The project uses only stable features and will only add dependencies that can compile on stable. It's a normal Rust project managed by Cargo, so you can compile with this simple command:

cargo build --release

The debug build really hurts performance, so unless you're doing a deep dive in the code it is recommended to compile for release.

Running

Basic usage:

xml-to-postgres <config.yml> [data.xml]

So the YAML configuration file is a required argument. The XML input file can be passed in as the second argument or will be read from stdin if omitted.

Example invocation:

xml-to-postgres config.yml data.xml > data.dump

Within a pipeline:

unzip -p xml.zip | xml-to-postgres config.yml | psql <database> -c '\copy <table> from stdin'

Within a database transaction:

xml-to-postgres config.yml data.xml | psql <database> -c 'BEGIN' -c 'TRUNCATE <table>' -c '\copy <table> from stdin' -c 'COMMIT'

Read multiple files in one go:

cat *.xml | xml-to-postgres config.yml > data.dump

Configuration

See the wiki for documentation on the configuration file and a basic example.

About

Fast tool to convert XML files with repeating element sets into PostgreSQL COPY format

Topics

conversionpostgresqlxml

Resources

Readme
GPL-3.0 license
Activity

Stars

10 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.