func newSingleModel(mod interface{}) (*singleModel, error) { model, ok := mod.(orm.Model) if !ok { var err error model, err = orm.NewModel(mod) if err != nil { return nil, err } } return &singleModel{ Model: model, }, nil }
func readExtQueryData(cn *pool.Conn, mod interface{}, columns []string) (res types.Result, e error) { coll, ok := mod.(orm.Collection) if !ok { coll, e = orm.NewModel(mod) if e != nil { coll = Discard } } var model orm.ColumnScanner for { c, msgLen, err := readMessageType(cn) if err != nil { return nil, err } switch c { case bindCompleteMsg: _, err := cn.ReadN(msgLen) if err != nil { return nil, err } case dataRowMsg: model = coll.NewModel() if err := readDataRow(cn, model, columns); err != nil { e = err } if err := coll.AddModel(model); err != nil { return nil, err } case commandCompleteMsg: // Response to the EXECUTE message. b, err := cn.ReadN(msgLen) if err != nil { return nil, err } res = types.ParseResult(b) case readyForQueryMsg: // Response to the SYNC message. _, err := cn.ReadN(msgLen) if err != nil { return nil, err } return case errorResponseMsg: var err error e, err = readError(cn) if err != nil { return nil, err } case noticeResponseMsg: if err := logNotice(cn, msgLen); err != nil { return nil, err } case parameterStatusMsg: if err := logParameterStatus(cn, msgLen); err != nil { return nil, err } default: if e != nil { return nil, e } return nil, fmt.Errorf("pg: readExtQueryData: unexpected message %#x", c) } } }