Where do you guys put the Back-End logic?
More specifically, how do you organise it? It is just a bunch of functions inside functions.
37 Replies
with trpc you can just call the function in the backend
but in general, you can split the routing logic to the business log
Domain Driven Design | SST
So we are ready to start working on our app. We'll be adding a simple comments feature to our Reddit clone. There are many ways of implementing this feature but with SST we want you to adopt a setup that'll scale as your app grows.
And how will I do that in t3 for example?
just a example
create a folder called "functions" or "core" or whatever
from trpc, you call those functions
if they require drizzle or whatever, just pass from the trpc context
Okay
And where do I store Models?
depends on what you are using
be prisma, drizzle or whatever
but you can just put everything on the trpc router
will work just fine
@zion_lg Here.
anyways just include it
like, you have a "where"
you can add an "include"
and include the todos
Like this?
Then?
should work now
anything that is another model need to be included, because prisma needs to perform seperate read requests to get these
These are all the options I get.
I think you need to await it first
do I have to await prisma calls as well?
Got it.
I was confused why are we not awaiting db calls. xD
yeah, tho if you dont need to user (or just need something like the user id) its better to use session context and query the todo's
btw, can I calls to the db now using
user.todos
?
It is my first day trying to use t3 xDwhich I just noticed you use input for it
you can use ctx.session.user.id
What if the user is not logged in?
use protectedProcedure
you dont have todo's if there is no user
also
using input like this is a privacy issue, since you allow for every user to get the todos of every user they want
I can be user x, and i can put in the input user y, and get his tasks
I know, I was just checking it out.
Still learning trpc.
ah okay
Is this possible?
Not sure I understand it
Suppose a Todo has children todos, like a tree structure.
How will I get access to its children?
I want to get the whole tree. Is that possible?
to my knowledge you'd have to do an include for each layer
the last layer will have the true
which is not a very good way
you can just use a query to get all of his todos, and have a reference to the child todo, than format it
if you want to have multiple children you can maybe have a refrence to the parent instead
That kind of ugly tbh.
Can I write my own SQL and have it set all the relations correctly?
you probably have to replace prisma for this
Btw, how expensive is the call from db?
GitHub
Tree structures support · Issue #4562 · prisma/prisma
Problem Hello! There is no real functionality for working with tree structures recursively. It would be awesome if there was a functionality added to define a model & query the most popular hie...
prisma is pretty expensive regarding reads tbf, but if you use something like planetscale its probably not an issue
maybe theres a workaround in the comments since this is still an open issue
It is still open 🥲
yep, there are some very annoying missing features that their issues were opened for years and still are
guess I will go back to ruby on rails. xD
How fast can I go from t3-app to fully PWA, desktop and mobile app?
Is there a way to put the app logic in the same location and use it both on the server and on client as well?
you can import whatever you want to both, you can make a utils folder or something and import the functions from there to both server and client
Nice.
I will just call raw sql with prisma and create my object there on the fly.