Hi Blind! Just started learning backend and java Right now I'm making my first simple CRUD app that interacts with the postgresql server using jdbc. I created a class that has 4 main methods: 1. createNewUser(String name) 2. updateUser(int userId, String newName) 3. deleteUser(int userId) 4. getUser(int userId) Is it the correct approach? And the main question here is whether or not my class should also contain a method to create that table I'm interacting with? How is it usually done in a real world apps? I'm assuming the tables are created manually through some query console and not via application code right?
World Conflicts
Yesterday
876
Israelies and Jews are great people
World Conflicts
Yesterday
239
Since people still can’t wrap their minds around the fact the Gaza death toll hasn’t changed
Tech Industry
Yesterday
1604
Meta E6 offer.
Layoffs
Yesterday
1138
We have 8 months left. They’re going to crash the economy once Trump is back.
Tech Industry
5h
923
How bad is it in meta?
You confused blind with stackoverflow
You're right
Sir, this is a Wendy’s.
Table creation is a DDL operation, while user management is a DML operation. For the purpose of security, the application should connect to the db in a restricted capacity (through a user with only the DML operation permissions) while table definition needs to be created using a higher privilege user. You can take a look at Flyway or Liquibase to manage schemas. They allow you to keep your database in a certain schema shape, that your application expects.
Also, I hope you mean four important methods and not four main() methods 😬
Table creation is infrastructure /deployment step. Write scripts, shouldn't be part of DAL
Using a tools like Liquibase/Flyway or an append only list of SQL statements. When going into production the append only list is preferable, so that a DBA can see exactly what you’re doing to their database. You know in case of data loss. But there are more freewheeling shops.
EDIT: I ended up answering the wrong question. But keeping it for reference. Depending on what you are building. Read Pattern of enterprise software architecture to understand various battle tested patterns. I will provide a TLDR; 1. Little to no domain logic: how many policies your business is dealing with? If there is only few ( or for emerging businesses policy’s often volatile), you better write your application as dirty as possible. In the industry they use Transaction Script (TS) to name it. A common technique is to use a controller -> service layer and handle presentation in the controller where implementing TS in service which directly talks to DB. Services should not depend on each other, so duplicates are allowed. 2. Domain Logic: your business talks about lots of policy (notice how bank, e-commerce or delivery works, too many small details). You better use some SOLID architecture. You can use onion architecture to isolate your domain and use DDD or other OOP patterns to keep your code maintainable. Write unit tests at onion boundary and if you have an internal layer, for that too. Every policy must be tested. 3. Middle ground: you can apply onion to isolate your business logic from infrastructure and presentation code. You are allowed to duplicate your code, as long as they do not bleed across boundaries. Be sure to switch to another heavier model when business gets complicated. In the end, it depends. You may want to prototype your app using TS. Release version 2 using onion + TS. If your business stays simple, you can continue this way. If lots of if-else creeps in, model only that part using OOP/SOLID/DDD and write unit test at interface boundary. Bonus: if you end up in big business with lots of policy and you see clear boundaries, you may apply microservices architecture. Each microservices must follow their own architecture thus only a handful will need your attention at SOLID/DDD level, others can live with onion+TS (if not replaced by an adapter layer to another third-party which is strongly encouraged!).
Nope created thru code, Infra as Code. use Terraform or CloudFormation for end to end real world table creation
Yes just execute via psql cli tool. The create table statement. Admin would do that once
Yup, mostly OPs team handles table creation, it should be a separate from main app.
Thank you very much!
Yo can you help me with my noob questions please? Can I dm you?