Garden App: Changing Database Hosting to Heroku Postgres

Rachela
1 min readAug 13, 2021

--

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()

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Rachela
Rachela

Written by Rachela

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

No responses yet

Write a response