admin icon indicating copy to clipboard operation
admin copied to clipboard

How to show entries from external DB (GRPC)

Open MarcSky opened this issue 6 years ago • 3 comments

Hello! I have a small question. In my project I want to get in the admin records from an external database. I get this data from Grpc. How can I draw them in the admin panel?

	r := adm.AddResource(&models.Notification{})

	r.FindManyHandler = func(result interface{}, context *qor.Context) error {
		getNotification := notificationGRPC.GetNotificationsReq{}
		res, err := notificationAccess.Client.GetNotifications(notificationAccess.Ctx, &getNotification)

		if _, ok := context.GetDB().Get("qor:getting_total_count"); ok {
			*(result.(*int)) = len(res.Notifications)
			return nil
		}

		var notificationViews = make([]models.Notification, len(res.Notifications))
		for i, v := range res.Notifications {
			n := models.Notification{}
			n.Title = v.Title
			notificationViews[i] = n
		}
		result = &notificationViews
		return nil
	}

type Notification struct {
	Title     string `json:"title"`
	Text      string `json:"text"`
	Type      string `json:"type"`
}

MarcSky avatar Jun 02 '19 17:06 MarcSky

this comment and the nosql issue #113 might help you.

cryptix avatar Jun 02 '19 21:06 cryptix

this comment and the nosql issue #113 might help you.

Thank you for help But I saw this and this doesn't help me ((

MarcSky avatar Jun 03 '19 09:06 MarcSky

I find solution

		var results = make([]*models.Notification, len(res.Notifications))
		for i, v := range res.Notifications {
			n := models.Notification{}
			n.Title = v.Title
			results[i] = &n
		}
		*(result.(*[]*models.Notification)) = results

MarcSky avatar Jun 04 '19 08:06 MarcSky