I have a posts table with few columns including a liked_by column which’s type is an int array. As I can’t post the table here I’ll post a single post’s JSON structure which comes as below I’m trying to send posts in the order they are liked (Most Liked Posts). Which should order…
Tag: go
Go SQL, scanning a row as a slice?
closing note: This question does not ask “how can I find the number of columns returned?” which is len(row.Columns()). It is asking a Go-related question concerning the rows.Scan() function. How can I extract all the columns in a row into a slice or equivalent? For example I would like to extract …
In go – gorm “mssql: Invalid column name ‘id’
This is my model in go } and this is my repo(that retrieve data from database): } On “http” I write this code with echo When I cal my ReadAll record rerieve data completly , it’s mean I conected to database currectly,But whene I try get data by “id” got an error that : mssql: Inv…
Implement Scan and Value functions in golang
I am trying to store some golang objects in SQL database and have implemented the scanner and value interface as follows: Is there a way that I can pass the parameter to the Value() function by pointers, as I am getting a HugeParam error that the attr passed to the Value() function is too big, when trying to …
Is it possible to omit FieldID in struct when using gorm?
Looking at an example from their documentation: CompanyID field seems rather redundant. Is it possible to get rid of it using some tags on Company field instead? Answer Changing User definition like this did the trick:
Multi-column IN/ANY postgres query
Sample table schema: Requirement: Fetch rows that match any of the tuples (col1, col2) presented in an array. SQL: I want to write this query in Go using the “database/sql” package with “github.com/lib/pq” driver, and that is where I am facing the problem. I can easily do this for sing…
How can i unlock the Database in Go
Im a newbie in go and not the best in sql. I have a simple Table in my Database with the name of users. I store the SAM, First Name and Last Name in the table. When i now try to change something in the database, i get the error database is locked. Thats my code: decodeJSONBody and checkError work
Doing 4 way filter based on 3 tables using GORM
I’ve been trying to achieve a 4 way to join/filter based on 4 tables “Offers”, “UserPaymentMethods” and a junction table “OffersUserPaymentMethods” defined as below; So I want to filter “offers” based on payment_method_id because offer_id lives in offers_u…
What is the best way to pass in authenticated user information to a sql query?
My web application uses a table users, posts and votes, where a user can create a post and the votes table contains single votes made by some user on some post (think of Hackernews or Reddit). When …
Create database transaction and commit/rollback later [closed]
Can we create database transaction and commit/rollback later. I mean we do not committing/rollback at the same machine/host/server. Let say we return the transaction and let other to decide to commit …