mirror of https://github.com/VinGarcia/ksql.git
Add Query & QueryNext funcs
parent
3f888e0420
commit
6c725a69f5
29
kiss_orm.go
29
kiss_orm.go
|
@ -17,6 +17,8 @@ type ORMProvider interface {
|
||||||
Update(ctx context.Context, intems ...interface{}) error
|
Update(ctx context.Context, intems ...interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Iterator interface{}
|
||||||
|
|
||||||
// Client ...
|
// Client ...
|
||||||
type Client struct {
|
type Client struct {
|
||||||
tableName string
|
tableName string
|
||||||
|
@ -63,6 +65,33 @@ func (c Client) Find(
|
||||||
return it.Error
|
return it.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query build an iterator for querying several
|
||||||
|
// results from the database
|
||||||
|
func (c Client) Query(
|
||||||
|
ctx context.Context,
|
||||||
|
query string,
|
||||||
|
params ...interface{},
|
||||||
|
) (Iterator, error) {
|
||||||
|
it := c.db.Raw(query, params...)
|
||||||
|
return it, it.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryNext parses the next row of a query
|
||||||
|
// and updates the item argument that must be
|
||||||
|
// passed by reference.
|
||||||
|
func (c Client) QueryNext(
|
||||||
|
ctx context.Context,
|
||||||
|
rawIt Iterator,
|
||||||
|
item interface{},
|
||||||
|
) error {
|
||||||
|
it, ok := rawIt.(*gorm.DB)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid iterator received on QueryNext()")
|
||||||
|
}
|
||||||
|
it.Scan(item)
|
||||||
|
return it.Error
|
||||||
|
}
|
||||||
|
|
||||||
// GetByID recovers a single entity from the database by the ID field.
|
// GetByID recovers a single entity from the database by the ID field.
|
||||||
func (c Client) GetByID(
|
func (c Client) GetByID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|
Loading…
Reference in New Issue