sql >> Database >  >> RDS >> PostgreSQL

verbinding maken met google cloud sql postgres-instantie van beam-pijplijn

U kunt de relational_db.Write . gebruiken en relational_db.Read transformeert van beam-nuggets als volgt:

Installeer eerst beam-nuggests:

pip install beam-nuggets

Om te lezen:

import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
from beam_nuggets.io import relational_db

with beam.Pipeline(options=PipelineOptions()) as p:
    source_config = relational_db.SourceConfiguration(
        drivername='postgresql+pg8000',
        host='localhost',
        port=5432,
        username='postgres',
        password='password',
        database='calendar',
    )
    records = p | "Reading records from db" >> relational_db.Read(
        source_config=source_config,
        table_name='months',
    )
    records | 'Writing to stdout' >> beam.Map(print)

Voor schrijven:

import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
from beam_nuggets.io import relational_db

with beam.Pipeline(options=PipelineOptions()) as p:
    months = p | "Reading month records" >> beam.Create([
        {'name': 'Jan', 'num': 1},
        {'name': 'Feb', 'num': 2},
    ])
    source_config = relational_db.SourceConfiguration(
        drivername='postgresql+pg8000',
        host='localhost',
        port=5432,
        username='postgres',
        password='password',
        database='calendar',
        create_if_missing=True,
    )
    table_config = relational_db.TableConfiguration(
        name='months',
        create_if_missing=True
    )
    months | 'Writing to DB' >> relational_db.Write(
        source_config=source_config,
        table_config=table_config
    )


  1. PhalconPHP-database sluit zich aan bij ORM

  2. Converteer tekstvak naar geheel getal

  3. AWS Python Lambda met Oracle

  4. Hoe gebruik je de native sql-functie met HQL-query?