Open plocket opened 1 year ago
Hi @thadk I am looking at this ticket. Since there is no back end, trying to understand where persistent data is being stored.
Does persistent data refer to the csv's such as Breslow natural-gas.csv
@jkoren Epic Stack and Remix host a javascript-based backend that access a SQL-based LiteDB/SQLite database via Prisma ORM, typically in the backend-based special loader
function in Remix JSX files. The loader
is great when you want to respond to a <form action/>
or GET request.
Here's an example where it queries the database to show all the users:
If we wanted to access this route via our root.tsx
, I think we just need to reintroduce children
into our body.
@jkoren Then, for each user, thenatural-gas.csv
might be stored in a table with a key associated with that user's entry in the user table in order to calculate their correct heat-pump size.
We had an idea of getting everything working in the browser before incorporating any persistence of this kind of data. Not sure if that'll end up being the best way forward or not.
If we still want to get everything working in the browser before incorporating any persistence, se should hold off on this ticket for now.
This is open to take now! Welcome.
I'm happy to take this on! I've got an epic-stack "Hello, World!" going on and will try to get some CRUD stuff going on there this week.
Hoping to follow this how-to to create a CRUD functionality: https://davelarrabee.com/a-simple-crud-app-in-remix
heat-stack-db
in ./heat-stack-db
Note: Make sure you have your .env
set up before running npm run dev
or any prisma migrations. Jake didn't copy .gitignore
file into the repo initially so we all might have to sync up on some secret files and such on a Tuesday.
app/routes/_marketing+/index.tsx
MockNotes
model in prisma/schema.prisma
npx prisma generate
then npx prisma migrate dev
(Camden and Jake aren't yet sure how these migrations happening in the cloud)POST
a new MockNote
/app/components/mock-heat-stack-form.tsx
buttonapp/routes/mock_notes/index.tsx
and returns all previous notes createdUsing this, we can hook into the action found in heat-stack/app/routes/_heat+/single.tsx
and interact with our Prisma client. On save, we can POST data to a not-yet-made table of user-form-data. On page load, we can load the most recent saved form-data associated with the logged in user 🎉
Out of scope... for now: Testing this in the cloud to see if the migrations run themselves or if we need to set up any custom CI/CD to run these migrations, or SSH into a fly.io server... or something like that. What am I? A DevOps expert?!
After talking with @plocket on Tuesday, this is a little bit of a more convoluted way to go about how Remix does things, which is to colocate client and server logic all in one place, and then split them up at compile time. This is to say, the button's onClick
handler could have just used the Prisma client directly! How about that?!
Here's an example of the above, a component using the Prisma client directly
Here is the commit relevant to replicating the process of creating a table with prisma and sqlite, then using remix actions to persist data in the database: https://github.com/codeforboston/home-energy-analysis-tool/commit/d337111dce965539a5fec0807b955a16dcc8a236
Note: As mentioned in the above comment, this is a little convoluted, we could have colocated all the action code with the button... but we didn't... don't follow these directions to a tee, but do take note of how the migrations were structured and whatnot. the "backend" code is correct.
heat-stack/types/index.ts
Existing
npm run prisma:studio
output onhome-energy-analysis-tool
but it may be slightly broken:Current error when you click on one in
home-energy-analysis-tool
: