Exporter Module

SQL export functionality for GS1 GPC.

This module provides classes for exporting database tables to SQL files.

The main class is GPCExporter which handles exporting GPC data from a SQLite database to SQL files. A legacy function is provided for backward compatibility but new code should use the GPCExporter class.

class gs1_gpc.exporter.GPCExporter(export_dir=None, language_code='en')[source]

Bases: object

Class for exporting GS1 GPC data from a database to SQL files.

This class provides methods to export GPC data from a SQLite database to SQL files. It extracts only the GPC-related tables (those with names starting with ‘gpc_’) and creates a SQL dump file that can be used to recreate the database.

__init__(export_dir=None, language_code='en')[source]

Initialize a GPCExporter.

Parameters:
  • export_dir (str, optional) – Directory where SQL files will be saved. If None, uses the default GPC_EXPORT_DIR.

  • language_code (str) – Language code to use in filenames (default: ‘en’)

dump_database_to_sql(db_file_path)[source]

Dump all GPC tables from the SQLite database to a SQL file.

This method extracts all tables with names starting with ‘gpc_’ from the specified SQLite database and creates a SQL dump file. The dump file includes both the table structure (CREATE statements) and the data (INSERT statements).

The SQL file is saved in the export directory with the naming convention: {language_code}-v{date}.sql

Parameters:

db_file_path (str) – Path to the SQLite database file

Returns:

Path to the SQL dump file or None if failed

Return type:

str

gs1_gpc.exporter.dump_database_to_sql(db_file_path, language_code='en', export_dir=None)[source]

Dump all GPC tables from the SQLite database to a SQL file.

This is a legacy function maintained for backward compatibility. New code should use the GPCExporter class instead.

Parameters:
  • db_file_path (str) – Path to the SQLite database file

  • language_code (str) – Language code to use in the filename

  • export_dir (str, optional) – Directory where SQL file will be saved

Returns:

Path to the SQL dump file or None if failed

Return type:

str