Files
ent/examples/edgeindex/ent/city.go
Alex Snast 9d9e121dbd ent/entc: .String() now uses ansic time format when formating time fields
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/103

Reviewed By: a8m

Differential Revision: D17978059

fbshipit-source-id: 721014b0bf712943d721c7ff038239cff690b94e
2019-10-17 04:36:04 -07:00

97 lines
2.4 KiB
Go

// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Code generated (@generated) by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"github.com/facebookincubator/ent/dialect/sql"
)
// City is the model entity for the City schema.
type City struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
}
// FromRows scans the sql response data into City.
func (c *City) FromRows(rows *sql.Rows) error {
var vc struct {
ID int
Name sql.NullString
}
// the order here should be the same as in the `city.Columns`.
if err := rows.Scan(
&vc.ID,
&vc.Name,
); err != nil {
return err
}
c.ID = vc.ID
c.Name = vc.Name.String
return nil
}
// QueryStreets queries the streets edge of the City.
func (c *City) QueryStreets() *StreetQuery {
return (&CityClient{c.config}).QueryStreets(c)
}
// Update returns a builder for updating this City.
// Note that, you need to call City.Unwrap() before calling this method, if this City
// was returned from a transaction, and the transaction was committed or rolled back.
func (c *City) Update() *CityUpdateOne {
return (&CityClient{c.config}).UpdateOne(c)
}
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
// so that all next queries will be executed through the driver which created the transaction.
func (c *City) Unwrap() *City {
tx, ok := c.config.driver.(*txDriver)
if !ok {
panic("ent: City is not a transactional entity")
}
c.config.driver = tx.drv
return c
}
// String implements the fmt.Stringer.
func (c *City) String() string {
var builder strings.Builder
builder.WriteString("City(")
builder.WriteString(fmt.Sprintf("id=%v", c.ID))
builder.WriteString(", name=")
builder.WriteString(c.Name)
builder.WriteByte(')')
return builder.String()
}
// Cities is a parsable slice of City.
type Cities []*City
// FromRows scans the sql response data into Cities.
func (c *Cities) FromRows(rows *sql.Rows) error {
for rows.Next() {
vc := &City{}
if err := vc.FromRows(rows); err != nil {
return err
}
*c = append(*c, vc)
}
return nil
}
func (c Cities) config(cfg config) {
for _i := range c {
c[_i].config = cfg
}
}