Skip to main content

Converts SQLALchemy Base Classes to AtlasGo HCL.

Project description

Summary

Converts SQLAlchemy models to AtlasGo HCL.

Quickstart

  • Run pip install sqlalchemy2atlas
  • Run sqlalchemy2atlas -h

Driver Support

  • PostgreSQL
    • 14.x
  • Cloud Spanner
  • MySQL
  • SQLLite

Example

Example of converting a SQLAlchemy module into AtlasGo HCL.

from datetime import datetime
from sqlalchemy.orm import declarative_base
from sqlalchemy import (
    Column,
    Integer,
    String,
    DateTime,
    CheckConstraint,
    ForeignKey,
)

Base = declarative_base()

class User(Base):
    __tablename__ = "user"

    # Feat: Primary Key
    id = Column(Integer, primary_key=True)

    # Feat: Column Types
    name = Column(String(30))
    full_name = Column(String)
    age = Column(Integer)

    # Feat: Check Constraints
    check_age_positive = CheckConstraint(age > 0)
    check_age_reasonable = CheckConstraint(age < 200)

class Account(Base):
    __tablename__ = "account"

    # Feat: Primary Key
    id = Column(Integer, primary_key=True)

    # Feat: Column Types, Foreign Keys
    user_id = Column(Integer, ForeignKey("user.id"), nullable=False)
    account_created_at = Column(DateTime, nullable=False)

Into

table "account" {
  schema = schema.public
  column "id" {
    null = false
    type = serial
  }
  column "user_id" {
    null = false
    type = integer
  }
  column "account_created_at" {
    null = false
    type = timestamp
  }
  primary_key {
    columns = [column.id]
  }
  foreign_key "account_user_id_fkey" {
    columns     = [column.user_id]
    ref_columns = [table.user.column.id]
    on_update   = NO_ACTION
    on_delete   = NO_ACTION
  }
}
table "user" {
  schema = schema.public
  column "id" {
    null = false
    type = serial
  }
  column "name" {
    null = true
    type = character_varying(30)
  }
  column "full_name" {
    null = true
    type = character_varying
  }
  column "age" {
    null = true
    type = integer
  }
  primary_key {
    columns = [column.id]
  }
  check "user_age_check" {
    expr = "(age > 0)"
  }
  check "user_age_check1" {
    expr = "(age < 200)"
  }
}
schema "public" {
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy2atlas-0.1.7.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy2atlas-0.1.7-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy2atlas-0.1.7.tar.gz.

File metadata

  • Download URL: sqlalchemy2atlas-0.1.7.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0

File hashes

Hashes for sqlalchemy2atlas-0.1.7.tar.gz
Algorithm Hash digest
SHA256 ba21d7f1ddc34757f792f66fe34967209fd1fbec8ced935a281ad235e3c68ba9
MD5 721544518721e8174f787d8c71ea276e
BLAKE2b-256 bfb2a0e537b81af6a367f6e9d2e6e419c4665b88ccd98138b776026941f07c16

See more details on using hashes here.

File details

Details for the file sqlalchemy2atlas-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy2atlas-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/21.6.0

File hashes

Hashes for sqlalchemy2atlas-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ae3526fe634abe8bb1844de24e72e59314f0ddec272c546e9a909c0d6d138b5c
MD5 a9e142531ccf694adc0a1fd5ceb1e514
BLAKE2b-256 fc5cdcb4af562eee011f83491337dea0bcb50c9176e935a1911741a0416804ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page