Skip to main content

Python Restfull API GAzie DB

Installazione

  1. PIP:
    pip install py_restfull_gazie
    

Adattare GAzie a CRUD PHP API

Procedure da Eseguire Su DB GAzie:

Prima di procedere occorre che il DB GAzie si pronto ad usare CRUD PHP API inserendo in tabella una chiave primaria 'id'.

Utilizzare lo script seguento per farlo.

DELIMITER //

DROP PROCEDURE IF EXISTS AddIdPrimaryKeyToGazie //

CREATE PROCEDURE AddIdPrimaryKeyToGazie()
BEGIN
    -- =========================================================================
    -- 1. TUTTE LE DICHIARAZIONI (Devono stare in cima)
    -- =========================================================================
    DECLARE done INT DEFAULT FALSE;
    DECLARE current_table VARCHAR(255);
    DECLARE old_pk_columns VARCHAR(512);
    
    -- Cursore per escludere tabelle con 'id' o con qualsiasi altro AUTO_INCREMENT
    DECLARE table_cursor CURSOR FOR 
        SELECT t.TABLE_NAME 
        FROM information_schema.TABLES t
        WHERE t.TABLE_SCHEMA = DATABASE()
          AND t.TABLE_NAME LIKE 'gaz_%'
          AND NOT EXISTS (
              SELECT 1 
              FROM information_schema.COLUMNS c 
              WHERE c.TABLE_SCHEMA = DATABASE() 
                AND c.TABLE_NAME = t.TABLE_NAME 
                AND c.COLUMN_NAME = 'id'
          )
          AND NOT EXISTS (
              SELECT 1 
              FROM information_schema.COLUMNS c 
              WHERE c.TABLE_SCHEMA = DATABASE() 
                AND c.TABLE_NAME = t.TABLE_NAME 
                AND c.EXTRA LIKE '%auto_increment%'
          );

    -- L'handler deve essere l'ultima cosa dichiarata
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;


    -- =========================================================================
    -- 2. ISTRUZIONI ESEGUIBILI
    -- =========================================================================
    
    -- Creazione della tabella temporanea per il LOG
    DROP TEMPORARY TABLE IF EXISTS temp_log_alter_tables;
    CREATE TEMPORARY TABLE temp_log_alter_tables (
        id INT AUTO_INCREMENT PRIMARY KEY,
        eseguito_alle TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        tabella_modificata VARCHAR(255),
        query_eseguita TEXT
    );

    OPEN table_cursor;

    read_loop: LOOP
        FETCH table_cursor INTO current_table;
        
        IF done THEN
            LEAVE read_loop;
        END IF;

        -- Recupera dinamicamente le colonne che compongono l'attuale chiave primaria
        SELECT GROUP_CONCAT(COLUMN_NAME SEPARATOR ', ')
        INTO old_pk_columns
        FROM information_schema.KEY_COLUMN_USAGE
        WHERE TABLE_SCHEMA = DATABASE()
          AND TABLE_NAME = current_table
          AND CONSTRAINT_NAME = 'PRIMARY';

        -- Se esiste una vecchia chiave primaria, procediamo
        IF old_pk_columns IS NOT NULL THEN
            
            SET @dynamic_sql = CONCAT(
                'ALTER TABLE `', current_table, '` ',
                'DROP PRIMARY KEY, ',
                'ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST, ',
                'ADD UNIQUE KEY `uk_', current_table, '_old_pk` (', old_pk_columns, ');'
            );

            -- Scrittura nel LOG
            INSERT INTO temp_log_alter_tables (tabella_modificata, query_eseguita) 
            VALUES (current_table, @dynamic_sql);

            -- Esecuzione della query
            PREPARE stmt FROM @dynamic_sql;
            EXECUTE stmt;
            DEALLOCATE PREPARE stmt;
            
        END IF;

    END LOOP;

    CLOSE table_cursor;
    
    -- 3. Stampa a schermo del risultato finale
    SELECT * FROM temp_log_alter_tables;
    
    -- Pulizia finale
    DROP TEMPORARY TABLE IF EXISTS temp_log_alter_tables;

END //

DELIMITER ;

Chiamare la Procedura

CALL AddIdPrimaryKeyToGazie();

Uso

Configurazione

Per la configurazione occore un file .env:

# Configurazione generica 
PREFIX_API=/contabile
GAZIE_URL=http://127.0.0.1:8082/modules/api/index.php
APP_TOKEN=test-token
PORT_EXPOSE=5002
DEVELOPMENT=true

Eseguire lo script api:

python -m py_restfull_gazie.main

Sia avviera' il server restfull api con swagger.

Release files for py-restfull-gazie 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-restfull-gazie 0.1.2
File Size Uploaded
py_restfull_gazie-0.1.2.tar.gz 29.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-restfull-gazie 0.1.2
File Interpreter ABI Platform
py_restfull_gazie-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 74.1 kB

Release files / py_restfull_gazie-0.1.2.tar.gz

Download URL py_restfull_gazie-0.1.2.tar.gz
Size 29.2 kB
Tags Source
SHA-256 checksum
How to use checksums
67e07536c5a16cb35f5c239a87e6fdd3a5afbaead6a45379e7c273b2119001aa
BLAKE2b-256 checksum
How to use checksums
6f33a0d0f6df4dcf728eac539e0addd0cd0e3a04799280accfb52df4ad23a9b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / py_restfull_gazie-0.1.2-py3-none-any.whl

Download URL py_restfull_gazie-0.1.2-py3-none-any.whl
Size 44.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
755a37bbc5e056e9fda740c6adc8abf2cd0c2d7aa876ebd7a418068f49e91c48
BLAKE2b-256 checksum
How to use checksums
cae9d1a992a423926c0ef323ccc6d17dd81d7ad82c0c21728e2a42a77111a13a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page