React Gin Blog (16/19): Custom database errors

Custom validation errors are added in previous chapter, but what about database errors? If you try to create account with already existing username, you will get error ERROR #23505 duplicate key value violates unique constraint “users_username_key”. Unfortunately, there is no validator involved here and pg module returns most of the errors as map[byte]string so thisContinue reading “React Gin Blog (16/19): Custom database errors”

React Gin Blog (14/19): Add user posts

With authentication in place, it is time to start using it. We will need authentication to create, read, update and delete user’s blog posts. Let’s start by adding new database migration which will create required data table with columns. Create new migration file migrations/2_addPostsTable.go: And then run migrations with: Now we create structure to holdContinue reading “React Gin Blog (14/19): Add user posts”

React Gin Blog (8/19): Migrations

With database created, we also need to create tables in which our data will be store. And best way to do that is using migrations. We will be using go-pg/migrations module. On GitHub page you can find basic installation and usage guide, and we will use that. Let’s start by creating new directory migrations/ insideContinue reading “React Gin Blog (8/19): Migrations”

React Gin Blog (7/19): Connecting with database

So far our backend is working very well. We can create user and login, but as soon we restart our server, that user data is lost, since it is saved only in memory while app is running. Of course that’s not realistic case and we want to save all user data even if server isContinue reading “React Gin Blog (7/19): Connecting with database”