entc/gen: load client bound to transaction once (#417)

Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
Alex Snast
2020-04-02 12:22:42 +03:00
committed by GitHub
parent 2ea4268414
commit 901c1394b4
25 changed files with 218 additions and 74 deletions

View File

@@ -21,6 +21,10 @@ type Tx struct {
// Street is the client for interacting with the Street builders.
Street *StreetClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -65,9 +69,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -19,6 +19,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -63,9 +67,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -21,6 +21,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -65,9 +69,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -19,6 +19,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -63,9 +67,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -19,6 +19,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -63,9 +67,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -21,6 +21,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -65,9 +69,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -19,6 +19,10 @@ type Tx struct {
// Node is the client for interacting with the Node builders.
Node *NodeClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -63,9 +67,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -21,6 +21,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -65,9 +69,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -19,6 +19,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -63,9 +67,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -19,6 +19,10 @@ type Tx struct {
// Node is the client for interacting with the Node builders.
Node *NodeClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -63,9 +67,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -23,6 +23,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -67,9 +71,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {

View File

@@ -23,6 +23,10 @@ type Tx struct {
// User is the client for interacting with the User builders.
User *UserClient
// lazily loaded.
client *Client
clientOnce sync.Once
// completion callbacks.
mu sync.Mutex
onCommit []func(error)
@@ -67,9 +71,11 @@ func (tx *Tx) OnRollback(f func(error)) {
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
client := &Client{config: tx.config}
client.init()
return client
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {