Skip to content

Commit 444aedd

Browse files
committed
readme
1 parent 23e7b65 commit 444aedd

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ func (u User) ConfigureEntity(e *orm.EntityConfigurator) {
8787

8888
func main() {
8989
// Setup ORM
90-
orm.Initialize(orm.ConnectionConfig{
90+
err := orm.Initialize(orm.ORMConfig{LogLevel: orm.LogLevelDev}, orm.ConnectionConfig{
9191
// Name: "default", // Optional. Specify connection names if you have more than on database.
9292
Driver: "sqlite3", // Database type. Currently supported sqlite3, mysql, mariadb, postgresql.
9393
ConnectionString: ":memory:", // Database DSN.
9494
})
9595

96+
if err != nil {
97+
panic(err)
98+
}
99+
96100
// Find user by primary key (ID)
97101
user, err := orm.Find[User](1)
98102

@@ -129,7 +133,7 @@ func (u User) ConfigureEntity(e *orm.EntityConfigurator) {
129133
```
130134
As you see, our user entity is nothing else than a simple struct and two methods.
131135
Entities in GolobbyORM are implementations of `Entity` interface, which defines two methods:
132-
- ConfigureEntity: configures table and also relations to other entities.
136+
- ConfigureEntity: configures table, fields, and also relations to other entities.
133137
#### Conventions
134138
##### Timestamps
135139
for having `created_at`, `updated_at`, `deleted_at` timestamps in your entities you can embed `orm.Timestamps` struct in your entity,

configurators.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,20 @@ type FieldConfigurator struct {
161161
isDeletedAt bool
162162
}
163163

164-
func (fc *FieldConfigurator) CanBeNull() *FieldConfigurator {
165-
fc.nullable = sql.NullBool{
166-
Bool: true,
167-
Valid: true,
168-
}
169-
return fc
170-
}
171-
func (fc *FieldConfigurator) CannotBeNull() *FieldConfigurator {
172-
fc.nullable = sql.NullBool{
173-
Bool: false,
174-
Valid: true,
175-
}
176-
return fc
177-
}
164+
//func (fc *FieldConfigurator) CanBeNull() *FieldConfigurator {
165+
// fc.nullable = sql.NullBool{
166+
// Bool: true,
167+
// Valid: true,
168+
// }
169+
// return fc
170+
//}
171+
//func (fc *FieldConfigurator) CannotBeNull() *FieldConfigurator {
172+
// fc.nullable = sql.NullBool{
173+
// Bool: false,
174+
// Valid: true,
175+
// }
176+
// return fc
177+
//}
178178

179179
func (fc *FieldConfigurator) IsPrimaryKey() *FieldConfigurator {
180180
fc.primaryKey = true

orm.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Schematic() {
2727
}
2828
}
2929

30-
type ORMConfig struct {
30+
type Config struct {
3131
//LogLevel
3232
LogLevel LogLevel
3333
}
@@ -55,12 +55,9 @@ type ConnectionConfig struct {
5555
}
5656

5757
//Initialize gets list of ConnectionConfig and builds up ORM for you.
58-
func Initialize(ormConfig *ORMConfig, configs ...ConnectionConfig) error {
58+
func Initialize(ormConfig Config, configs ...ConnectionConfig) error {
5959
//configure logger
6060
var err error
61-
if ormConfig == nil {
62-
ormConfig = &ORMConfig{}
63-
}
6461
if ormConfig.LogLevel == 0 {
6562
ormConfig.LogLevel = LogLevelDev
6663
}

orm_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (p Post) ConfigureEntity(e *orm.EntityConfigurator) {
4646
HasOne(AuthorEmail{}, orm.HasOneConfig{}).
4747
BelongsToMany(Category{}, orm.BelongsToManyConfig{IntermediateTable: "post_categories"}).
4848
Fields().
49-
Field("ID").CanBeNull().IsPrimaryKey().ColumnName("id").
49+
Field("ID").IsPrimaryKey().ColumnName("id").
5050
Also().
5151
Field("BodyText").ColumnName("body")
5252

@@ -92,7 +92,7 @@ func (c Category) Posts() ([]Post, error) {
9292
// Errors should be carried
9393

9494
func setup(t *testing.T) {
95-
err := orm.Initialize(nil, orm.ConnectionConfig{
95+
err := orm.Initialize(orm.Config{}, orm.ConnectionConfig{
9696
Driver: "sqlite3",
9797
ConnectionString: ":memory:",
9898
Entities: []orm.Entity{&Post{}, &Comment{}, &Category{}, &HeaderPicture{}},

schema_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func setup(t *testing.T) {
10-
err := Initialize(nil, ConnectionConfig{
10+
err := Initialize(Config{}, ConnectionConfig{
1111
Driver: "sqlite3",
1212
ConnectionString: ":memory:",
1313
})

0 commit comments

Comments
 (0)