Giter VIP home page Giter VIP logo

bigorm's Introduction

bigorm

This project was created before the official SQLAlchemy dialect for BigQuery was released. Now that the official dialect is released, this project is deprecated.

This project provides an abstract base class mimicing sqlalchemy's declarative base class which can be used to create a declarative mapping to BigQueryTables. This base class wraps a number of the expected sqlalchemy functionality to support interacting with BigQuery as well as providing new BigQuery specific functionality. Declaring models and querying tables should be familiar to users of sqlalchemy with most sqlalchemy types supported. This is no concept of a session when interacting with BigQuery through the wrapped ORM. At the time of writing, BigQuery did not support primary keys.

import datetime
import pandas as pd
from sqlalchemy import Float, Integer, DateTime
from bigorm.abstract_models import BigQueryModel as Model, BigQueryColumn as Column
from bigorm.database import BigQueryDatabaseContext as DatabaseContext


class Example(Model):

    __tablename__ = 'example_dataset.example'  # The table will be named 'example' in the dataset 'example_dataset'
    example_integer = Column(Integer)  # Creates a column in the table named 'example_integer'
    example_float_property = Column(Float, nullable=False)  # Create a property that is not allowed to be empty with nullable=False

    # Create a column that automatically gets populated with the current datetime (when the object instance is created)
    example_date_created = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)

with DatabaseContext(project='example_project'):
    if not Example.table_exists():
        Example.table_create()

    dataframe = pd.DataFrame({
        'example_float_property': [1.1, 2.2, 5.2],
        'example_date_created': [datetime.datetime.utcnow()] * 3,
        'example_integer_labeled_differently': [None, 3, None],
    })
    Example.create_from_pandas(
        df=dataframe,
        relabel={
            'example_integer_labeled_differently': 'example_integer'
        },
        create_method='load_job'
    )

    query_df = Example.query().all_as_pandas()

See Examples.md in docs folder.

bigorm's People

Contributors

anthonyperez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.