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