scany icon indicating copy to clipboard operation
scany copied to clipboard

Is scany thread safe ?

Open charbelcs123 opened this issue 1 year ago • 2 comments

type ServiceOverview struct { ServiceId uint64 db:"ID" SubscriptionId uint64 db:"SUB_ID" StatusId int32 db:"STATUS_ID" }

const SelectSubscriptionOverviewSql string = SELECT TO_CHAR(s.id) as ID, TO_CHAR(s.SUBSCRIPTION_ID) as SUB_ID, s.STATUS_ID FROM Service

func (d *Dao) GetServiceOverviews(ctx context.Context, accountId uint64, bgId uint64) ([]ServiceOverview, error) {

var sos []ServiceOverview
err := sqlscan.Select(ctx, d.rDb, &sos, SelectSubscriptionOverviewSql, accountId, bgId)
return sos, err

}

I am getting the following error: scanning one: scanning: doing scan: scanFn: scany: column: 'A_NUMBER': no corresponding field found, or it's unexported in models.ServiceOverview

Please note that A_NUMBER is not present in SelectSubscriptionOverviewSql

charbelcs123 avatar May 16 '24 11:05 charbelcs123

Hi, this is an interesting issue. Yes, scany is thread-safe, as long as your underlying driver library instance, d.rDb, is thread-safe. To debug this, I would recommend printing SelectSubscriptionOverviewSql and executing it on the database directly (without scany) to see what columns it returns right before where you get the error.

georgysavva avatar May 19 '24 11:05 georgysavva

Ok, Thank you for clearing that out, Usually the query works, and then the process starts crashing after a while with random errors for different queries Maybe i am missing something, I am not sure.

charbelcs123 avatar May 20 '24 10:05 charbelcs123