Skip to content

Commit 3a8ee5c

Browse files
committed
README
1 parent a62cc35 commit 3a8ee5c

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ user, err := orm.Find[User](1)
148148
You can also use custom queries to get entities from database.
149149
```go
150150

151-
user, err := orm.Query[User]().Where("id", 1).One()
152-
user, err := orm.Query[User]().WherePK(1).One()
151+
user, err := orm.Query[User]().Where("id", 1).First()
152+
user, err := orm.Query[User]().WherePK(1).First()
153153
```
154154
GolobbyORM contains a powerful query builder which you can use to build `Select`, `Update` and `Delete` queries, but if you want to write a raw sql query you can.
155155
```go
@@ -238,7 +238,7 @@ func (c Comment) ConfigureEntity(e *orm.EntityConfigurator) {
238238
As you can see we are defining a `Comment` entity which has a `BelongsTo` relation with `Post` that we saw earlier. You can configure how GolobbyORM queries `BelongsTo` relation with `orm.BelongsToConfig` object, by default it will infer all fields for you.
239239
now you can use this relationship anywhere in your code.
240240
```go
241-
post, err := orm.BelongsTo[Post](comment)
241+
post, err := orm.BelongsTo[Post](comment).First()
242242
```
243243
#### BelongsToMany
244244
```go
@@ -257,7 +257,7 @@ func(c Category) ConfigureEntity(r *orm.EntityConfigurator) {
257257
we are defining a `Post` entity and also a `Category` entity which have a many2many relationship, as you can see it's mandatory for us to configure IntermediateTable name which GolobbyORM cannot infer by itself now.
258258
now you can use this relationship anywhere in your code.
259259
```go
260-
categories, err := orm.BelongsToMany[Category](post)
260+
categories, err := orm.BelongsToMany[Category](post).All()
261261
```
262262
#### Saving with relation
263263
You may need to save an entity which has some kind of relation with another entity, in that case you can use `Add` method.

orm.go

+1-21
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func Update(obj Entity) error {
258258
// Delete given Entity from database
259259
func Delete(obj Entity) error {
260260
s := getSchemaFor(obj)
261-
261+
genericSet(obj, "deleted_at", sql.NullTime{Time: time.Now(), Valid: true})
262262
query, args, err := NewQueryBuilder[Entity]().SetDialect(s.getDialect()).Table(s.Table).Where(s.pkName(), genericGetPKValue(obj)).SetDelete().ToSql()
263263
if err != nil {
264264
return err
@@ -456,26 +456,6 @@ func addBelongsToMany(to Entity, items ...Entity) error {
456456
return nil
457457
}
458458

459-
//func Query[OUTPUT Entity](s *QueryBuilder[OUTPUT]) ([]OUTPUT, error) {
460-
// o := new(OUTPUT)
461-
// sch := getSchemaFor(*o)
462-
// s.SetDialect(sch.dialect).Table(sch.Table).SetSelect()
463-
// q, args, err := s.ToSql()
464-
// if err != nil {
465-
// return nil, err
466-
// }
467-
// rows, err := getSchemaFor(*o).getSQLDB().Query(q, args...)
468-
// if err != nil {
469-
// return nil, err
470-
// }
471-
// var output []OUTPUT
472-
// err = getSchemaFor(*o).bind(rows, &output)
473-
// if err != nil {
474-
// return nil, err
475-
// }
476-
// return output, nil
477-
//}
478-
479459
func Query[E Entity]() *QueryBuilder[E] {
480460
q := NewQueryBuilder[E]()
481461
s := getSchemaFor(*new(E))

0 commit comments

Comments
 (0)