liveBook · Manning

SQLAlchemy

As explained in Build Financial Software with Generative AI (From Scratch)

SQLAlchemy is a Python library and ORM toolkit for working with relational databases through SQL expressions and mapped objects.

SQLAlchemy is an object-relational mapper (ORM) for working with SQL databases through application code. It abstracts database details, supports database-agnostic development, and can improve productivity, while existing software standards should guide adoption. section 5.1

Choose SQLAlchemy as part of a deliberate database implementation workflow:

  • Start with the database design, then define tests, build tables and fields, and expose the API. section 5.1
  • Compare ORM-based development with direct SQL: SQL offers control, while ORMs simplify common database work. section 5.1
  • Check complex queries, performance, troubleshooting, and maintenance expectations before committing to an ORM. section 5.1
Listing 5.1 PlantUML definition of our database
@startuml #1

object ach_file_uploads { #2
    ach_files_id: UUID   #3
    filename: VARCHAR(255)  #3
    file_hash: VARCHAR(32)  #3
    credit_total: NUMERIC(12,2)  #3
    debit_total: NUMERIC(12,2)  #3
}

object ach_files {
    ach_files_id: UUID
    record_type: VARCHAR(1)
    record_id: UUID
    parsed: BOOLEAN    
    sequence: NUMERIC
    unparsed_record: VARCHAR(94)
}

object ach_file_header_records {
    record_id: UUID
    fields for record type
}

object ach_batch_header_records {
    record_id: UUID
    file_header_id: UUID
    fields for record type  
}

object ach_entry_detail_ppd_records {
    record_id: UUID
    batch_header_id: UUID
    fields for record type
}

object ach_addenda_ppd_records {
    record_id: UUID
    entry_detail_id: UUID
    fields for record type
}

object ach_batch_control_records {
    record_id: UUID
    batch_header_id: UUID
    fields for record type
}

object ach_file_control_records {
    record_id: UUID
    file_header_id: UUID
    fields for record type
}

ach_file_uploads::ach_files_id <-- ach_files::ach_files_id  #4
 #4
ach_files::record_id <-- ach_file_header_records::record_id #4
ach_files::record_id <-- ach_batch_header_records::record_id #4
ach_files::record_id <-- ach_entry_detail_ppd_records::record_id #4
ach_files::record_id <-- ach_addenda_ppd_records::record_id #4
ach_files::record_id <-- ach_batch_control_records::record_id #4
ach_files::record_id <-- ach_file_control_records::record_id #4
 #4
ach_batch_header_records::file_header_id -> 
ach_file_header_records::record_id #4 ach_entry_detail_ppd_records::batch_header_id ->
ach_batch_header_records::record_id #4 ach_addenda_ppd_records::entry_detail_id ->
ach_entry_detail_ppd_records::record_id #4 ach_batch_control_records::batch_header_id -->
ach_batch_header_records::record_id #4 ach_file_control_records::file_header_id -->
ach_file_header_records::record_id #4 #4 @enduml #5

Use the ACH database definition and table-relationship diagram to connect ORM decisions with a concrete relational schema. section 5.1

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Contrasts ORM benefits and limitations with direct SQL but stops short of detailed SQLAlchemy implementation.
Examples
Uses an ACH-file schema, PlantUML table definition, and table-relationship diagram as concrete design artifacts.
What it assumes
Builds on database diagrams, SQL commands, table-and-field design, testing, and API construction.
What you can do after
Apply it via SQLAlchemy after comparing direct SQL, project standards, query complexity, and maintenance costs.
How it connects
Connects object-relational mapping with SQL, relational databases, database schemas, APIs, testing, and query performance.

Also explained in

Compare how 4 books explain SQLAlchemy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.