Garden App: Changing Database Hosting to Heroku Postgres

I was struggling with using SQLite and the memory on Android phone, but I switched to Heroku Postgres as my SQL database hosting service. Since I was using SQLAlchemy, all I needed to do was change the pathway from SQLite to Heroku in the create_engine() command.

This is my main app init function. I made it so that there was a central place for all screens to easily access the database connection information. See below the MainApp code to learn how to access this information from any screen on the app.

class MainApp(App):

def __init__(self, **kwargs):
super(MainApp, self).__init__(**kwargs)
self.meta = MetaData()
self.engine = create_engine("postgres://, echo=True)
self.conn = self.engine.connect()
self.my_plants = Table(
"plants", self.meta,
Column("id", Integer, primary_key=True),
Column("name", String),
Column("common_name", String),
Column("category", String),
Column("location", String),
Column("year", Integer),
Column("notes", String),
)
self.gardens = Table(
"gardens", self.meta,
Column("id", Integer, primary_key=True),
Column("name", String),
Column("notes", String),
)
self.meta.create_all(self.engine)
def get_garden_records(self):
search = self.gardens.select(self.gardens)
return self.conn.execute(search)

def build(self):
self.title = "My Gardens App"
return RootWidget()

You can access anything in the App class using this syntax:

.py

from kivy.app import App# ---- access my_plants table ---- #
my_plants_table = App.get_running_app().my_plants

.kv

# ---- accessing a function ---- #
Button:
text: "My Gardens"
on_release: app.get_garden_records()

--

--

--

I am a librarian and new computer programmer creating an app with Python and Kivy to document the plants in my garden.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why does the Signal Processing Toolbox 6.1 (R13SP1) cause

Spring Boot Guide for Beginner: Hello World

Most Important Java Interview Questions and Answers

It all comes down to timing — A quick guide to Timeline in Unity

DolphinDB Partitioned Database Tutorial

Making a switch from QA to Dev

Programming Is an Art — Stop Treating It Like It’s Not

How to Keep Your Dependencies Up to Date with npm and Yarn

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rachela

Rachela

I am a librarian and new computer programmer creating an app with Python and Kivy to document the plants in my garden.

More from Medium

How to export excel properly with Flask and Ajax Call

How to create a secure OTP service with twilio verify and python

DJANGO — CREATING A PROJECT

[Ubuntu 20.04][MySQL5.7]Problems installing mysql5.7 on Ubuntu 20.04