PGX Implementation | 220108


210108 ~ 210122

Had wood to cut and snow to clear, plus trying to dev on generator power and LTE got old. Granted it suppose to snow again tomorrow(today)…

PGX Server Crud is in a working state.

that code has been pushed to Conduit - Github

For the Server service the CRUD operation is in working in some form testing is still needed, but its there. GORM has been replaced with pgx database interface.

It has some growing pain cause I am not sure where to put the sql that I am calling.

pgx, If so?How to?

also link to pgx https://github.com/jackc/pgx

There are few new things

Example

Okay there are a few ways to connect to the database ‘ConnPool’ was what I used was cause it is concurrency-safe. Granted I haven’t added anything that needs thread safety, but I don’t this to mess with that when and if I get to it (docs: Link to Go Docs)

Okay there are a few ways to connect to the database ‘ConnPool’ was what I used was cause it is concurrency-safe. Granted I haven’t added anything that needs thread safety, but I don’t this to mess with that when and if I get to it (docs: Link to Go Docs)

pgx pool

Each service will have it own DBConnPool cause each them will have their own db user _ Each service will have it own DBConnPool cause each them will have their own db user _

ServerServiceSetup

On the topic that each service will have it own database and user I am keeping that in code as well for init setup of each of them. I have not set any way to have this created yet, but will be use full later.

I plan on have a db user that creates database users for each of the necessary services with there associated databases. Then each of those service users would check and create any missing table or add missing fields, add necessary db extension

Its complicated and you could argue that its not necessary, but this adds some flexibility and keeps it so each of the services can’t access any other service database(With the necessary perms in place.(Postgres: Revoke Doc)

_ Okay back to the code above On the topic that each service will have it own database and user I am keeping that in code as well for init setup of each of them. I have not set any way to have this created yet, but will be use full later.

I plan on have a db user that creates database users for each of the necessary services with there associated databases. Then each of those service users would check and create any missing table or add missing fields, add necessary db extension

Its complicated and you could argue that its not necessary, but this adds some flexibility and keeps it so each of the services can’t access any other service database(With the necessary perms in place.(Postgres: Revoke Doc)

_ Okay back to the code above Scany

scany package: https://github.com/georgysavva/scany

So this allows mapping of the database response to a go struct. Just make sure you sent it the address of a pointer like seen above so it can handle nils for other structs.

Scany with the use of tags knows with is what is mapped where. (image below)

scany package: https://github.com/georgysavva/scany

So this allows mapping of the database response to a go struct. Just make sure you sent it the address of a pointer like seen above so it can handle nils for other structs.

Scany with the use of tags knows with is what is mapped where. (image below)

db tag useage.

Model Updates

Looking at the model changes I wanted to point out some things

UUID

What is UUID: big’ol slug delimited alphanumeric unique id There are a few different version of it, but they should work each other for the most part, I am using a v4 which is just determined by a random number. I will be using this for all non trivial models with in this project. I am letting the database create these upon insertion.

Model Updates

Looking at the model changes I wanted to point out some things

UUID

What is UUID: big’ol slug delimited alphanumeric unique id There are a few different version of it, but they should work each other for the most part, I am using a v4 which is just determined by a random number. I will be using this for all non trivial models with in this project. I am letting the database create these upon insertion.

Server Model Schema

There were two places in the REST code that need to change to accommodate this change. For the Delete and Get Singleton cause the ID is passed in the URI

  • The Router part to accepted the long boi of an id There were two places in the REST code that need to change to accommodate this change. For the Delete and Get Singleton cause the ID is passed in the URI

  • The Router part to accepted the long boi of an id getRouter

  • Then grabbing the UUID from the URL string to UUID conversion

Currently I am using the “github.com/gofrs/uuid” pakage for the UUID it seems to work and has those conversion helper functions.

Currently I am using the “github.com/gofrs/uuid” pakage for the UUID it seems to work and has those conversion helper functions.

Postman Example

SoftDelete

SoftDelete: To not really delete, but just mark deleted and hide it

If look back in the model you’ll see i have time fields for create,update, and delete.

SoftDelete

SoftDelete: To not really delete, but just mark deleted and hide it

If look back in the model you’ll see i have time fields for create,update, and delete.

Server Table

Instead of deleting the row I am updating the time of the transaction on the code side

Instead of deleting the row I am updating the time of the transaction on the code side

Delete Function

So this a fairly easy to do it just like the update function. Where some challenge comes in is with retrieval

So this a fairly easy to do it just like the update function. Where some challenge comes in is with retrieval

Get all Servers

The way I am hiding the “deleted” images is removing any server that has a populated ‘deleted_at’ field once the all server(s) are returned in code with a function called “removeSoftDeletedItems()” which just iterates over the array and removes the servers with said popped field and returns the clean array.

I know I can do with a better sql select statement, but I will look at timings later cause the only reason I would pick one over the other would be speed or security. Plus replacing it with a sql statement would quick.

So instead of getting all seven servers in this you only get the five that are not “deleted” The way I am hiding the “deleted” images is removing any server that has a populated ‘deleted_at’ field once the all server(s) are returned in code with a function called “removeSoftDeletedItems()” which just iterates over the array and removes the servers with said popped field and returns the clean array.

I know I can do with a better sql select statement, but I will look at timings later cause the only reason I would pick one over the other would be speed or security. Plus replacing it with a sql statement would quick.

So instead of getting all seven servers in this you only get the five that are not “deleted” postman get all servers Server Table

“Status” Field

So this field will be for the Saga micro service pattern implementation the saga pattern can lacks isolation when you have more than one moving and grooving about. So that status field will be Semantic lock used like a flag for other sages to notice that a transaction is being perform on this obj and to handle it(waiting or whatever).

So I know I need one of these, but still not positive all the details for implementation for my use case. I don’ think it will really be used all much at the server or channel lvl, but messages and user seem like they need to further explored and will get to that when arrive at that bridge

“Status” Field

So this field will be for the Saga micro service pattern implementation the saga pattern can lacks isolation when you have more than one moving and grooving about. So that status field will be Semantic lock used like a flag for other sages to notice that a transaction is being perform on this obj and to handle it(waiting or whatever).

So I know I need one of these, but still not positive all the details for implementation for my use case. I don’ think it will really be used all much at the server or channel lvl, but messages and user seem like they need to further explored and will get to that when arrive at that bridge

Status

Whats Next

I have a few options here.

  • I can just copy pasta why thur channel and messages to rip out and replace the existing gorm
  • Figure out where I am going to put the Servers_Users Table
  • Get Users to some state existing
  • State the Sage process

Not positive what the next play is, but should one or two of these.


Forward, Stay warm.