Database Module
Database operations for GS1 GPC.
This module provides functions for setting up and interacting with the database, including creating tables and inserting data.
- class gs1_gpc.db.DatabaseConnection(connection_string, db_type='sqlite')[source]
Bases:
objectDatabase connection abstraction for SQLite and PostgreSQL.
- gs1_gpc.db.setup_database(db_connection)[source]
Create GPC tables if they don’t exist.
The schema uses junction tables for the many-to-many relationships between bricks and attribute types, and between attribute types and attribute values. In the GS1 GPC XML, the same attribute type can appear on many bricks, and the same attribute value can appear under many attribute types. Previous versions used single foreign keys which silently dropped these relationships via INSERT OR IGNORE.
- Parameters:
db_connection (DatabaseConnection) – Database connection object
- Returns:
True if successful, False otherwise
- Return type:
- gs1_gpc.db.insert_family(cursor, family_code, description, segment_code)[source]
Insert a family record.
- gs1_gpc.db.insert_class(cursor, class_code, description, family_code)[source]
Insert a class record.
- gs1_gpc.db.insert_brick(cursor, brick_code, description, class_code)[source]
Insert a brick record.
- gs1_gpc.db.insert_attribute_type(cursor, att_type_code, att_type_text, brick_code)[source]
Insert an attribute type record and link it to a brick.
Inserts the attribute type into the global table (if not already present) and creates the brick-to-attribute-type junction record.