repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
howeyc/fsnotify | fsnotify_bsd.go | Close | func (w *Watcher) Close() error {
w.mu.Lock()
if w.isClosed {
w.mu.Unlock()
return nil
}
w.isClosed = true
w.mu.Unlock()
// Send "quit" message to the reader goroutine
w.done <- true
w.wmut.Lock()
ws := w.watches
w.wmut.Unlock()
for path := range ws {
w.removeWatch(path)
}
return nil
} | go | func (w *Watcher) Close() error {
w.mu.Lock()
if w.isClosed {
w.mu.Unlock()
return nil
}
w.isClosed = true
w.mu.Unlock()
// Send "quit" message to the reader goroutine
w.done <- true
w.wmut.Lock()
ws := w.watches
w.wmut.Unlock()
for path := range ws {
w.removeWatch(path)
}
return nil
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"Close",
"(",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"w",
".",
"isClosed",
"{",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"w",
".",
"isClosed",
"=",
"true",
"\n",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Send \"quit\" message to the reader goroutine",
"w",
".",
"done",
"<-",
"true",
"\n",
"w",
".",
"wmut",
".",
"Lock",
"(",
")",
"\n",
"ws",
":=",
"w",
".",
"watches",
"\n",
"w",
".",
"wmut",
".",
"Unlock",
"(",
")",
"\n",
"for",
"path",
":=",
"range",
"ws",
"{",
"w",
".",
"removeWatch",
"(",
"path",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close closes a kevent watcher instance
// It sends a message to the reader goroutine to quit and removes all watches
// associated with the kevent instance | [
"Close",
"closes",
"a",
"kevent",
"watcher",
"instance",
"It",
"sends",
"a",
"message",
"to",
"the",
"reader",
"goroutine",
"to",
"quit",
"and",
"removes",
"all",
"watches",
"associated",
"with",
"the",
"kevent",
"instance"
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_bsd.go#L113-L132 | train |
howeyc/fsnotify | fsnotify_bsd.go | sendDirectoryChangeEvents | func (w *Watcher) sendDirectoryChangeEvents(dirPath string) {
// Get all files
files, err := ioutil.ReadDir(dirPath)
if err != nil {
w.Error <- err
}
// Search for new files
for _, fileInfo := range files {
filePath := filepath.Join(dirPath, fileInfo.Name())
w.femut.Lock()
_, doesExist := w.fileExists[filePath]
w.femut.Unlock()
if !doesExist {
// Inherit fsnFlags from parent directory
w.fsnmut.Lock()
if flags, found := w.fsnFlags[dirPath]; found {
w.fsnFlags[filePath] = flags
} else {
w.fsnFlags[filePath] = FSN_ALL
}
w.fsnmut.Unlock()
// Send create event
fileEvent := new(FileEvent)
fileEvent.Name = filePath
fileEvent.create = true
w.internalEvent <- fileEvent
}
w.femut.Lock()
w.fileExists[filePath] = true
w.femut.Unlock()
}
w.watchDirectoryFiles(dirPath)
} | go | func (w *Watcher) sendDirectoryChangeEvents(dirPath string) {
// Get all files
files, err := ioutil.ReadDir(dirPath)
if err != nil {
w.Error <- err
}
// Search for new files
for _, fileInfo := range files {
filePath := filepath.Join(dirPath, fileInfo.Name())
w.femut.Lock()
_, doesExist := w.fileExists[filePath]
w.femut.Unlock()
if !doesExist {
// Inherit fsnFlags from parent directory
w.fsnmut.Lock()
if flags, found := w.fsnFlags[dirPath]; found {
w.fsnFlags[filePath] = flags
} else {
w.fsnFlags[filePath] = FSN_ALL
}
w.fsnmut.Unlock()
// Send create event
fileEvent := new(FileEvent)
fileEvent.Name = filePath
fileEvent.create = true
w.internalEvent <- fileEvent
}
w.femut.Lock()
w.fileExists[filePath] = true
w.femut.Unlock()
}
w.watchDirectoryFiles(dirPath)
} | [
"func",
"(",
"w",
"*",
"Watcher",
")",
"sendDirectoryChangeEvents",
"(",
"dirPath",
"string",
")",
"{",
"// Get all files",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"dirPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"Error",
"<-",
"err",
"\n",
"}",
"\n\n",
"// Search for new files",
"for",
"_",
",",
"fileInfo",
":=",
"range",
"files",
"{",
"filePath",
":=",
"filepath",
".",
"Join",
"(",
"dirPath",
",",
"fileInfo",
".",
"Name",
"(",
")",
")",
"\n",
"w",
".",
"femut",
".",
"Lock",
"(",
")",
"\n",
"_",
",",
"doesExist",
":=",
"w",
".",
"fileExists",
"[",
"filePath",
"]",
"\n",
"w",
".",
"femut",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"doesExist",
"{",
"// Inherit fsnFlags from parent directory",
"w",
".",
"fsnmut",
".",
"Lock",
"(",
")",
"\n",
"if",
"flags",
",",
"found",
":=",
"w",
".",
"fsnFlags",
"[",
"dirPath",
"]",
";",
"found",
"{",
"w",
".",
"fsnFlags",
"[",
"filePath",
"]",
"=",
"flags",
"\n",
"}",
"else",
"{",
"w",
".",
"fsnFlags",
"[",
"filePath",
"]",
"=",
"FSN_ALL",
"\n",
"}",
"\n",
"w",
".",
"fsnmut",
".",
"Unlock",
"(",
")",
"\n\n",
"// Send create event",
"fileEvent",
":=",
"new",
"(",
"FileEvent",
")",
"\n",
"fileEvent",
".",
"Name",
"=",
"filePath",
"\n",
"fileEvent",
".",
"create",
"=",
"true",
"\n",
"w",
".",
"internalEvent",
"<-",
"fileEvent",
"\n",
"}",
"\n",
"w",
".",
"femut",
".",
"Lock",
"(",
")",
"\n",
"w",
".",
"fileExists",
"[",
"filePath",
"]",
"=",
"true",
"\n",
"w",
".",
"femut",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"w",
".",
"watchDirectoryFiles",
"(",
"dirPath",
")",
"\n",
"}"
] | // sendDirectoryEvents searches the directory for newly created files
// and sends them over the event channel. This functionality is to have
// the BSD version of fsnotify match linux fsnotify which provides a
// create event for files created in a watched directory. | [
"sendDirectoryEvents",
"searches",
"the",
"directory",
"for",
"newly",
"created",
"files",
"and",
"sends",
"them",
"over",
"the",
"event",
"channel",
".",
"This",
"functionality",
"is",
"to",
"have",
"the",
"BSD",
"version",
"of",
"fsnotify",
"match",
"linux",
"fsnotify",
"which",
"provides",
"a",
"create",
"event",
"for",
"files",
"created",
"in",
"a",
"watched",
"directory",
"."
] | f0c08ee9c60704c1879025f2ae0ff3e000082c13 | https://github.com/howeyc/fsnotify/blob/f0c08ee9c60704c1879025f2ae0ff3e000082c13/fsnotify_bsd.go#L462-L496 | train |
coreos/go-oidc | jwks.go | NewRemoteKeySet | func NewRemoteKeySet(ctx context.Context, jwksURL string) KeySet {
return newRemoteKeySet(ctx, jwksURL, time.Now)
} | go | func NewRemoteKeySet(ctx context.Context, jwksURL string) KeySet {
return newRemoteKeySet(ctx, jwksURL, time.Now)
} | [
"func",
"NewRemoteKeySet",
"(",
"ctx",
"context",
".",
"Context",
",",
"jwksURL",
"string",
")",
"KeySet",
"{",
"return",
"newRemoteKeySet",
"(",
"ctx",
",",
"jwksURL",
",",
"time",
".",
"Now",
")",
"\n",
"}"
] | // NewRemoteKeySet returns a KeySet that can validate JSON web tokens by using HTTP
// GETs to fetch JSON web token sets hosted at a remote URL. This is automatically
// used by NewProvider using the URLs returned by OpenID Connect discovery, but is
// exposed for providers that don't support discovery or to prevent round trips to the
// discovery URL.
//
// The returned KeySet is a long lived verifier that caches keys based on cache-control
// headers. Reuse a common remote key set instead of creating new ones as needed.
//
// The behavior of the returned KeySet is undefined once the context is canceled. | [
"NewRemoteKeySet",
"returns",
"a",
"KeySet",
"that",
"can",
"validate",
"JSON",
"web",
"tokens",
"by",
"using",
"HTTP",
"GETs",
"to",
"fetch",
"JSON",
"web",
"token",
"sets",
"hosted",
"at",
"a",
"remote",
"URL",
".",
"This",
"is",
"automatically",
"used",
"by",
"NewProvider",
"using",
"the",
"URLs",
"returned",
"by",
"OpenID",
"Connect",
"discovery",
"but",
"is",
"exposed",
"for",
"providers",
"that",
"don",
"t",
"support",
"discovery",
"or",
"to",
"prevent",
"round",
"trips",
"to",
"the",
"discovery",
"URL",
".",
"The",
"returned",
"KeySet",
"is",
"a",
"long",
"lived",
"verifier",
"that",
"caches",
"keys",
"based",
"on",
"cache",
"-",
"control",
"headers",
".",
"Reuse",
"a",
"common",
"remote",
"key",
"set",
"instead",
"of",
"creating",
"new",
"ones",
"as",
"needed",
".",
"The",
"behavior",
"of",
"the",
"returned",
"KeySet",
"is",
"undefined",
"once",
"the",
"context",
"is",
"canceled",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/jwks.go#L36-L38 | train |
coreos/go-oidc | jwks.go | done | func (i *inflight) done(keys []jose.JSONWebKey, err error) {
i.keys = keys
i.err = err
close(i.doneCh)
} | go | func (i *inflight) done(keys []jose.JSONWebKey, err error) {
i.keys = keys
i.err = err
close(i.doneCh)
} | [
"func",
"(",
"i",
"*",
"inflight",
")",
"done",
"(",
"keys",
"[",
"]",
"jose",
".",
"JSONWebKey",
",",
"err",
"error",
")",
"{",
"i",
".",
"keys",
"=",
"keys",
"\n",
"i",
".",
"err",
"=",
"err",
"\n",
"close",
"(",
"i",
".",
"doneCh",
")",
"\n",
"}"
] | // done can only be called by a single goroutine. It records the result of the
// inflight request and signals other goroutines that the result is safe to
// inspect. | [
"done",
"can",
"only",
"be",
"called",
"by",
"a",
"single",
"goroutine",
".",
"It",
"records",
"the",
"result",
"of",
"the",
"inflight",
"request",
"and",
"signals",
"other",
"goroutines",
"that",
"the",
"result",
"is",
"safe",
"to",
"inspect",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/jwks.go#L85-L89 | train |
coreos/go-oidc | jwks.go | keysFromRemote | func (r *remoteKeySet) keysFromRemote(ctx context.Context) ([]jose.JSONWebKey, error) {
// Need to lock to inspect the inflight request field.
r.mu.Lock()
// If there's not a current inflight request, create one.
if r.inflight == nil {
r.inflight = newInflight()
// This goroutine has exclusive ownership over the current inflight
// request. It releases the resource by nil'ing the inflight field
// once the goroutine is done.
go func() {
// Sync keys and finish inflight when that's done.
keys, expiry, err := r.updateKeys()
r.inflight.done(keys, err)
// Lock to update the keys and indicate that there is no longer an
// inflight request.
r.mu.Lock()
defer r.mu.Unlock()
if err == nil {
r.cachedKeys = keys
r.expiry = expiry
}
// Free inflight so a different request can run.
r.inflight = nil
}()
}
inflight := r.inflight
r.mu.Unlock()
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-inflight.wait():
return inflight.result()
}
} | go | func (r *remoteKeySet) keysFromRemote(ctx context.Context) ([]jose.JSONWebKey, error) {
// Need to lock to inspect the inflight request field.
r.mu.Lock()
// If there's not a current inflight request, create one.
if r.inflight == nil {
r.inflight = newInflight()
// This goroutine has exclusive ownership over the current inflight
// request. It releases the resource by nil'ing the inflight field
// once the goroutine is done.
go func() {
// Sync keys and finish inflight when that's done.
keys, expiry, err := r.updateKeys()
r.inflight.done(keys, err)
// Lock to update the keys and indicate that there is no longer an
// inflight request.
r.mu.Lock()
defer r.mu.Unlock()
if err == nil {
r.cachedKeys = keys
r.expiry = expiry
}
// Free inflight so a different request can run.
r.inflight = nil
}()
}
inflight := r.inflight
r.mu.Unlock()
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-inflight.wait():
return inflight.result()
}
} | [
"func",
"(",
"r",
"*",
"remoteKeySet",
")",
"keysFromRemote",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"jose",
".",
"JSONWebKey",
",",
"error",
")",
"{",
"// Need to lock to inspect the inflight request field.",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"// If there's not a current inflight request, create one.",
"if",
"r",
".",
"inflight",
"==",
"nil",
"{",
"r",
".",
"inflight",
"=",
"newInflight",
"(",
")",
"\n\n",
"// This goroutine has exclusive ownership over the current inflight",
"// request. It releases the resource by nil'ing the inflight field",
"// once the goroutine is done.",
"go",
"func",
"(",
")",
"{",
"// Sync keys and finish inflight when that's done.",
"keys",
",",
"expiry",
",",
"err",
":=",
"r",
".",
"updateKeys",
"(",
")",
"\n\n",
"r",
".",
"inflight",
".",
"done",
"(",
"keys",
",",
"err",
")",
"\n\n",
"// Lock to update the keys and indicate that there is no longer an",
"// inflight request.",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"r",
".",
"cachedKeys",
"=",
"keys",
"\n",
"r",
".",
"expiry",
"=",
"expiry",
"\n",
"}",
"\n\n",
"// Free inflight so a different request can run.",
"r",
".",
"inflight",
"=",
"nil",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"inflight",
":=",
"r",
".",
"inflight",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"ctx",
".",
"Err",
"(",
")",
"\n",
"case",
"<-",
"inflight",
".",
"wait",
"(",
")",
":",
"return",
"inflight",
".",
"result",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // keysFromRemote syncs the key set from the remote set, records the values in the
// cache, and returns the key set. | [
"keysFromRemote",
"syncs",
"the",
"key",
"set",
"from",
"the",
"remote",
"set",
"records",
"the",
"values",
"in",
"the",
"cache",
"and",
"returns",
"the",
"key",
"set",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/jwks.go#L151-L190 | train |
coreos/go-oidc | verify.go | Verifier | func (p *Provider) Verifier(config *Config) *IDTokenVerifier {
return NewVerifier(p.issuer, p.remoteKeySet, config)
} | go | func (p *Provider) Verifier(config *Config) *IDTokenVerifier {
return NewVerifier(p.issuer, p.remoteKeySet, config)
} | [
"func",
"(",
"p",
"*",
"Provider",
")",
"Verifier",
"(",
"config",
"*",
"Config",
")",
"*",
"IDTokenVerifier",
"{",
"return",
"NewVerifier",
"(",
"p",
".",
"issuer",
",",
"p",
".",
"remoteKeySet",
",",
"config",
")",
"\n",
"}"
] | // Verifier returns an IDTokenVerifier that uses the provider's key set to verify JWTs.
//
// The returned IDTokenVerifier is tied to the Provider's context and its behavior is
// undefined once the Provider's context is canceled. | [
"Verifier",
"returns",
"an",
"IDTokenVerifier",
"that",
"uses",
"the",
"provider",
"s",
"key",
"set",
"to",
"verify",
"JWTs",
".",
"The",
"returned",
"IDTokenVerifier",
"is",
"tied",
"to",
"the",
"Provider",
"s",
"context",
"and",
"its",
"behavior",
"is",
"undefined",
"once",
"the",
"Provider",
"s",
"context",
"is",
"canceled",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/verify.go#L98-L100 | train |
coreos/go-oidc | verify.go | resolveDistributedClaim | func resolveDistributedClaim(ctx context.Context, verifier *IDTokenVerifier, src claimSource) ([]byte, error) {
req, err := http.NewRequest("GET", src.Endpoint, nil)
if err != nil {
return nil, fmt.Errorf("malformed request: %v", err)
}
if src.AccessToken != "" {
req.Header.Set("Authorization", "Bearer "+src.AccessToken)
}
resp, err := doRequest(ctx, req)
if err != nil {
return nil, fmt.Errorf("oidc: Request to endpoint failed: %v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unable to read response body: %v", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("oidc: request failed: %v", resp.StatusCode)
}
token, err := verifier.Verify(ctx, string(body))
if err != nil {
return nil, fmt.Errorf("malformed response body: %v", err)
}
return token.claims, nil
} | go | func resolveDistributedClaim(ctx context.Context, verifier *IDTokenVerifier, src claimSource) ([]byte, error) {
req, err := http.NewRequest("GET", src.Endpoint, nil)
if err != nil {
return nil, fmt.Errorf("malformed request: %v", err)
}
if src.AccessToken != "" {
req.Header.Set("Authorization", "Bearer "+src.AccessToken)
}
resp, err := doRequest(ctx, req)
if err != nil {
return nil, fmt.Errorf("oidc: Request to endpoint failed: %v", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("unable to read response body: %v", err)
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("oidc: request failed: %v", resp.StatusCode)
}
token, err := verifier.Verify(ctx, string(body))
if err != nil {
return nil, fmt.Errorf("malformed response body: %v", err)
}
return token.claims, nil
} | [
"func",
"resolveDistributedClaim",
"(",
"ctx",
"context",
".",
"Context",
",",
"verifier",
"*",
"IDTokenVerifier",
",",
"src",
"claimSource",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"src",
".",
"Endpoint",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"src",
".",
"AccessToken",
"!=",
"\"",
"\"",
"{",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"src",
".",
"AccessToken",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"doRequest",
"(",
"ctx",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"token",
",",
"err",
":=",
"verifier",
".",
"Verify",
"(",
"ctx",
",",
"string",
"(",
"body",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"token",
".",
"claims",
",",
"nil",
"\n",
"}"
] | // Returns the Claims from the distributed JWT token | [
"Returns",
"the",
"Claims",
"from",
"the",
"distributed",
"JWT",
"token"
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/verify.go#L124-L154 | train |
coreos/go-oidc | oidc.go | Claims | func (u *UserInfo) Claims(v interface{}) error {
if u.claims == nil {
return errors.New("oidc: claims not set")
}
return json.Unmarshal(u.claims, v)
} | go | func (u *UserInfo) Claims(v interface{}) error {
if u.claims == nil {
return errors.New("oidc: claims not set")
}
return json.Unmarshal(u.claims, v)
} | [
"func",
"(",
"u",
"*",
"UserInfo",
")",
"Claims",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"u",
".",
"claims",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"u",
".",
"claims",
",",
"v",
")",
"\n",
"}"
] | // Claims unmarshals the raw JSON object claims into the provided object. | [
"Claims",
"unmarshals",
"the",
"raw",
"JSON",
"object",
"claims",
"into",
"the",
"provided",
"object",
"."
] | 66476e0267012774b2f9767d2d37a317d1f1aac3 | https://github.com/coreos/go-oidc/blob/66476e0267012774b2f9767d2d37a317d1f1aac3/oidc.go#L172-L177 | train |
scylladb/gocqlx | qb/utils.go | placeholders | func placeholders(cql *bytes.Buffer, count int) {
if count < 1 {
return
}
for i := 0; i < count-1; i++ {
cql.WriteByte('?')
cql.WriteByte(',')
}
cql.WriteByte('?')
} | go | func placeholders(cql *bytes.Buffer, count int) {
if count < 1 {
return
}
for i := 0; i < count-1; i++ {
cql.WriteByte('?')
cql.WriteByte(',')
}
cql.WriteByte('?')
} | [
"func",
"placeholders",
"(",
"cql",
"*",
"bytes",
".",
"Buffer",
",",
"count",
"int",
")",
"{",
"if",
"count",
"<",
"1",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
"-",
"1",
";",
"i",
"++",
"{",
"cql",
".",
"WriteByte",
"(",
"'?'",
")",
"\n",
"cql",
".",
"WriteByte",
"(",
"','",
")",
"\n",
"}",
"\n",
"cql",
".",
"WriteByte",
"(",
"'?'",
")",
"\n",
"}"
] | // placeholders returns a string with count ? placeholders joined with commas. | [
"placeholders",
"returns",
"a",
"string",
"with",
"count",
"?",
"placeholders",
"joined",
"with",
"commas",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/utils.go#L12-L22 | train |
scylladb/gocqlx | qb/update.go | Table | func (b *UpdateBuilder) Table(table string) *UpdateBuilder {
b.table = table
return b
} | go | func (b *UpdateBuilder) Table(table string) *UpdateBuilder {
b.table = table
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Table",
"(",
"table",
"string",
")",
"*",
"UpdateBuilder",
"{",
"b",
".",
"table",
"=",
"table",
"\n",
"return",
"b",
"\n",
"}"
] | // Table sets the table to be updated. | [
"Table",
"sets",
"the",
"table",
"to",
"be",
"updated",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L77-L80 | train |
scylladb/gocqlx | qb/update.go | Set | func (b *UpdateBuilder) Set(columns ...string) *UpdateBuilder {
for _, c := range columns {
b.assignments = append(b.assignments, assignment{
column: c,
value: param(c),
})
}
return b
} | go | func (b *UpdateBuilder) Set(columns ...string) *UpdateBuilder {
for _, c := range columns {
b.assignments = append(b.assignments, assignment{
column: c,
value: param(c),
})
}
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Set",
"(",
"columns",
"...",
"string",
")",
"*",
"UpdateBuilder",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"columns",
"{",
"b",
".",
"assignments",
"=",
"append",
"(",
"b",
".",
"assignments",
",",
"assignment",
"{",
"column",
":",
"c",
",",
"value",
":",
"param",
"(",
"c",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"b",
"\n",
"}"
] | // Set adds SET clauses to the query. | [
"Set",
"adds",
"SET",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L108-L117 | train |
scylladb/gocqlx | qb/update.go | SetNamed | func (b *UpdateBuilder) SetNamed(column, name string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: param(name)})
return b
} | go | func (b *UpdateBuilder) SetNamed(column, name string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: param(name)})
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"SetNamed",
"(",
"column",
",",
"name",
"string",
")",
"*",
"UpdateBuilder",
"{",
"b",
".",
"assignments",
"=",
"append",
"(",
"b",
".",
"assignments",
",",
"assignment",
"{",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
"}",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // SetNamed adds SET column=? clause to the query with a custom parameter name. | [
"SetNamed",
"adds",
"SET",
"column",
"=",
"?",
"clause",
"to",
"the",
"query",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L120-L124 | train |
scylladb/gocqlx | qb/update.go | SetLit | func (b *UpdateBuilder) SetLit(column, literal string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: lit(literal)})
return b
} | go | func (b *UpdateBuilder) SetLit(column, literal string) *UpdateBuilder {
b.assignments = append(
b.assignments, assignment{column: column, value: lit(literal)})
return b
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"SetLit",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"UpdateBuilder",
"{",
"b",
".",
"assignments",
"=",
"append",
"(",
"b",
".",
"assignments",
",",
"assignment",
"{",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
"}",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // SetLit adds SET column=literal clause to the query. | [
"SetLit",
"adds",
"SET",
"column",
"=",
"literal",
"clause",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L127-L131 | train |
scylladb/gocqlx | qb/update.go | Add | func (b *UpdateBuilder) Add(column string) *UpdateBuilder {
return b.addValue(column, param(column))
} | go | func (b *UpdateBuilder) Add(column string) *UpdateBuilder {
return b.addValue(column, param(column))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Add",
"(",
"column",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"addValue",
"(",
"column",
",",
"param",
"(",
"column",
")",
")",
"\n",
"}"
] | // Add adds SET column=column+? clauses to the query. | [
"Add",
"adds",
"SET",
"column",
"=",
"column",
"+",
"?",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L140-L142 | train |
scylladb/gocqlx | qb/update.go | AddNamed | func (b *UpdateBuilder) AddNamed(column, name string) *UpdateBuilder {
return b.addValue(column, param(name))
} | go | func (b *UpdateBuilder) AddNamed(column, name string) *UpdateBuilder {
return b.addValue(column, param(name))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"AddNamed",
"(",
"column",
",",
"name",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"addValue",
"(",
"column",
",",
"param",
"(",
"name",
")",
")",
"\n",
"}"
] | // AddNamed adds SET column=column+? clauses to the query with a custom
// parameter name. | [
"AddNamed",
"adds",
"SET",
"column",
"=",
"column",
"+",
"?",
"clauses",
"to",
"the",
"query",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L146-L148 | train |
scylladb/gocqlx | qb/update.go | AddLit | func (b *UpdateBuilder) AddLit(column, literal string) *UpdateBuilder {
return b.addValue(column, lit(literal))
} | go | func (b *UpdateBuilder) AddLit(column, literal string) *UpdateBuilder {
return b.addValue(column, lit(literal))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"AddLit",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"addValue",
"(",
"column",
",",
"lit",
"(",
"literal",
")",
")",
"\n",
"}"
] | // AddLit adds SET column=column+literal clauses to the query. | [
"AddLit",
"adds",
"SET",
"column",
"=",
"column",
"+",
"literal",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L151-L153 | train |
scylladb/gocqlx | qb/update.go | Remove | func (b *UpdateBuilder) Remove(column string) *UpdateBuilder {
return b.removeValue(column, param(column))
} | go | func (b *UpdateBuilder) Remove(column string) *UpdateBuilder {
return b.removeValue(column, param(column))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"Remove",
"(",
"column",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"removeValue",
"(",
"column",
",",
"param",
"(",
"column",
")",
")",
"\n",
"}"
] | // Remove adds SET column=column-? clauses to the query. | [
"Remove",
"adds",
"SET",
"column",
"=",
"column",
"-",
"?",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L170-L172 | train |
scylladb/gocqlx | qb/update.go | RemoveNamed | func (b *UpdateBuilder) RemoveNamed(column, name string) *UpdateBuilder {
return b.removeValue(column, param(name))
} | go | func (b *UpdateBuilder) RemoveNamed(column, name string) *UpdateBuilder {
return b.removeValue(column, param(name))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"RemoveNamed",
"(",
"column",
",",
"name",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"removeValue",
"(",
"column",
",",
"param",
"(",
"name",
")",
")",
"\n",
"}"
] | // RemoveNamed adds SET column=column-? clauses to the query with a custom
// parameter name. | [
"RemoveNamed",
"adds",
"SET",
"column",
"=",
"column",
"-",
"?",
"clauses",
"to",
"the",
"query",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L176-L178 | train |
scylladb/gocqlx | qb/update.go | RemoveLit | func (b *UpdateBuilder) RemoveLit(column, literal string) *UpdateBuilder {
return b.removeValue(column, lit(literal))
} | go | func (b *UpdateBuilder) RemoveLit(column, literal string) *UpdateBuilder {
return b.removeValue(column, lit(literal))
} | [
"func",
"(",
"b",
"*",
"UpdateBuilder",
")",
"RemoveLit",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"UpdateBuilder",
"{",
"return",
"b",
".",
"removeValue",
"(",
"column",
",",
"lit",
"(",
"literal",
")",
")",
"\n",
"}"
] | // RemoveLit adds SET column=column-literal clauses to the query. | [
"RemoveLit",
"adds",
"SET",
"column",
"=",
"column",
"-",
"literal",
"clauses",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/update.go#L181-L183 | train |
scylladb/gocqlx | queryx.go | Query | func Query(q *gocql.Query, names []string) *Queryx {
return &Queryx{
Query: q,
Names: names,
Mapper: DefaultMapper,
}
} | go | func Query(q *gocql.Query, names []string) *Queryx {
return &Queryx{
Query: q,
Names: names,
Mapper: DefaultMapper,
}
} | [
"func",
"Query",
"(",
"q",
"*",
"gocql",
".",
"Query",
",",
"names",
"[",
"]",
"string",
")",
"*",
"Queryx",
"{",
"return",
"&",
"Queryx",
"{",
"Query",
":",
"q",
",",
"Names",
":",
"names",
",",
"Mapper",
":",
"DefaultMapper",
",",
"}",
"\n",
"}"
] | // Query creates a new Queryx from gocql.Query using a default mapper. | [
"Query",
"creates",
"a",
"new",
"Queryx",
"from",
"gocql",
".",
"Query",
"using",
"a",
"default",
"mapper",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L92-L98 | train |
scylladb/gocqlx | queryx.go | BindStruct | func (q *Queryx) BindStruct(arg interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg, nil, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | go | func (q *Queryx) BindStruct(arg interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg, nil, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"BindStruct",
"(",
"arg",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"arglist",
",",
"err",
":=",
"bindStructArgs",
"(",
"q",
".",
"Names",
",",
"arg",
",",
"nil",
",",
"q",
".",
"Mapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"q",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"q",
".",
"err",
"=",
"nil",
"\n",
"q",
".",
"Bind",
"(",
"arglist",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"q",
"\n",
"}"
] | // BindStruct binds query named parameters to values from arg using mapper. If
// value cannot be found error is reported. | [
"BindStruct",
"binds",
"query",
"named",
"parameters",
"to",
"values",
"from",
"arg",
"using",
"mapper",
".",
"If",
"value",
"cannot",
"be",
"found",
"error",
"is",
"reported",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L102-L112 | train |
scylladb/gocqlx | queryx.go | BindStructMap | func (q *Queryx) BindStructMap(arg0 interface{}, arg1 map[string]interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg0, arg1, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | go | func (q *Queryx) BindStructMap(arg0 interface{}, arg1 map[string]interface{}) *Queryx {
arglist, err := bindStructArgs(q.Names, arg0, arg1, q.Mapper)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"BindStructMap",
"(",
"arg0",
"interface",
"{",
"}",
",",
"arg1",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"arglist",
",",
"err",
":=",
"bindStructArgs",
"(",
"q",
".",
"Names",
",",
"arg0",
",",
"arg1",
",",
"q",
".",
"Mapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"q",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"q",
".",
"err",
"=",
"nil",
"\n",
"q",
".",
"Bind",
"(",
"arglist",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"q",
"\n",
"}"
] | // BindStructMap binds query named parameters to values from arg0 and arg1
// using a mapper. If value cannot be found in arg0 it's looked up in arg1
// before reporting an error. | [
"BindStructMap",
"binds",
"query",
"named",
"parameters",
"to",
"values",
"from",
"arg0",
"and",
"arg1",
"using",
"a",
"mapper",
".",
"If",
"value",
"cannot",
"be",
"found",
"in",
"arg0",
"it",
"s",
"looked",
"up",
"in",
"arg1",
"before",
"reporting",
"an",
"error",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L117-L127 | train |
scylladb/gocqlx | queryx.go | BindMap | func (q *Queryx) BindMap(arg map[string]interface{}) *Queryx {
arglist, err := bindMapArgs(q.Names, arg)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | go | func (q *Queryx) BindMap(arg map[string]interface{}) *Queryx {
arglist, err := bindMapArgs(q.Names, arg)
if err != nil {
q.err = fmt.Errorf("bind error: %s", err)
} else {
q.err = nil
q.Bind(arglist...)
}
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"BindMap",
"(",
"arg",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"arglist",
",",
"err",
":=",
"bindMapArgs",
"(",
"q",
".",
"Names",
",",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"q",
".",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"q",
".",
"err",
"=",
"nil",
"\n",
"q",
".",
"Bind",
"(",
"arglist",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"q",
"\n",
"}"
] | // BindMap binds query named parameters using map. | [
"BindMap",
"binds",
"query",
"named",
"parameters",
"using",
"map",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L157-L167 | train |
scylladb/gocqlx | queryx.go | Exec | func (q *Queryx) Exec() error {
if q.err != nil {
return q.err
}
return q.Query.Exec()
} | go | func (q *Queryx) Exec() error {
if q.err != nil {
return q.err
}
return q.Query.Exec()
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"Exec",
"(",
")",
"error",
"{",
"if",
"q",
".",
"err",
"!=",
"nil",
"{",
"return",
"q",
".",
"err",
"\n",
"}",
"\n",
"return",
"q",
".",
"Query",
".",
"Exec",
"(",
")",
"\n",
"}"
] | // Exec executes the query without returning any rows. | [
"Exec",
"executes",
"the",
"query",
"without",
"returning",
"any",
"rows",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L188-L193 | train |
scylladb/gocqlx | queryx.go | Get | func (q *Queryx) Get(dest interface{}) error {
if q.err != nil {
return q.err
}
return Iter(q.Query).Get(dest)
} | go | func (q *Queryx) Get(dest interface{}) error {
if q.err != nil {
return q.err
}
return Iter(q.Query).Get(dest)
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"q",
".",
"err",
"!=",
"nil",
"{",
"return",
"q",
".",
"err",
"\n",
"}",
"\n",
"return",
"Iter",
"(",
"q",
".",
"Query",
")",
".",
"Get",
"(",
"dest",
")",
"\n",
"}"
] | // Get scans first row into a destination. If the destination type is a struct
// pointer, then Iter.StructScan will be used. If the destination is some
// other type, then the row must only have one column which can scan into that
// type.
//
// If no rows were selected, ErrNotFound is returned. | [
"Get",
"scans",
"first",
"row",
"into",
"a",
"destination",
".",
"If",
"the",
"destination",
"type",
"is",
"a",
"struct",
"pointer",
"then",
"Iter",
".",
"StructScan",
"will",
"be",
"used",
".",
"If",
"the",
"destination",
"is",
"some",
"other",
"type",
"then",
"the",
"row",
"must",
"only",
"have",
"one",
"column",
"which",
"can",
"scan",
"into",
"that",
"type",
".",
"If",
"no",
"rows",
"were",
"selected",
"ErrNotFound",
"is",
"returned",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L208-L213 | train |
scylladb/gocqlx | queryx.go | GetRelease | func (q *Queryx) GetRelease(dest interface{}) error {
defer q.Release()
return q.Get(dest)
} | go | func (q *Queryx) GetRelease(dest interface{}) error {
defer q.Release()
return q.Get(dest)
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"GetRelease",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"q",
".",
"Release",
"(",
")",
"\n",
"return",
"q",
".",
"Get",
"(",
"dest",
")",
"\n",
"}"
] | // GetRelease calls Get and releases the query, a released query cannot be
// reused. | [
"GetRelease",
"calls",
"Get",
"and",
"releases",
"the",
"query",
"a",
"released",
"query",
"cannot",
"be",
"reused",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L217-L220 | train |
scylladb/gocqlx | queryx.go | SelectRelease | func (q *Queryx) SelectRelease(dest interface{}) error {
defer q.Release()
return q.Select(dest)
} | go | func (q *Queryx) SelectRelease(dest interface{}) error {
defer q.Release()
return q.Select(dest)
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"SelectRelease",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"q",
".",
"Release",
"(",
")",
"\n",
"return",
"q",
".",
"Select",
"(",
"dest",
")",
"\n",
"}"
] | // SelectRelease calls Select and releases the query, a released query cannot be
// reused. | [
"SelectRelease",
"calls",
"Select",
"and",
"releases",
"the",
"query",
"a",
"released",
"query",
"cannot",
"be",
"reused",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx.go#L237-L240 | train |
scylladb/gocqlx | iterx.go | Get | func Get(dest interface{}, q *gocql.Query) error {
return Iter(q).Get(dest)
} | go | func Get(dest interface{}, q *gocql.Query) error {
return Iter(q).Get(dest)
} | [
"func",
"Get",
"(",
"dest",
"interface",
"{",
"}",
",",
"q",
"*",
"gocql",
".",
"Query",
")",
"error",
"{",
"return",
"Iter",
"(",
"q",
")",
".",
"Get",
"(",
"dest",
")",
"\n",
"}"
] | // Get is a convenience function for creating iterator and calling Get.
//
// DEPRECATED use Queryx.Get or Queryx.GetRelease. | [
"Get",
"is",
"a",
"convenience",
"function",
"for",
"creating",
"iterator",
"and",
"calling",
"Get",
".",
"DEPRECATED",
"use",
"Queryx",
".",
"Get",
"or",
"Queryx",
".",
"GetRelease",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L19-L21 | train |
scylladb/gocqlx | iterx.go | Select | func Select(dest interface{}, q *gocql.Query) error {
return Iter(q).Select(dest)
} | go | func Select(dest interface{}, q *gocql.Query) error {
return Iter(q).Select(dest)
} | [
"func",
"Select",
"(",
"dest",
"interface",
"{",
"}",
",",
"q",
"*",
"gocql",
".",
"Query",
")",
"error",
"{",
"return",
"Iter",
"(",
"q",
")",
".",
"Select",
"(",
"dest",
")",
"\n",
"}"
] | // Select is a convenience function for creating iterator and calling Select.
//
// DEPRECATED use Queryx.Select or Queryx.SelectRelease. | [
"Select",
"is",
"a",
"convenience",
"function",
"for",
"creating",
"iterator",
"and",
"calling",
"Select",
".",
"DEPRECATED",
"use",
"Queryx",
".",
"Select",
"or",
"Queryx",
".",
"SelectRelease",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L26-L28 | train |
scylladb/gocqlx | iterx.go | Iter | func Iter(q *gocql.Query) *Iterx {
return &Iterx{
Iter: q.Iter(),
Mapper: DefaultMapper,
}
} | go | func Iter(q *gocql.Query) *Iterx {
return &Iterx{
Iter: q.Iter(),
Mapper: DefaultMapper,
}
} | [
"func",
"Iter",
"(",
"q",
"*",
"gocql",
".",
"Query",
")",
"*",
"Iterx",
"{",
"return",
"&",
"Iterx",
"{",
"Iter",
":",
"q",
".",
"Iter",
"(",
")",
",",
"Mapper",
":",
"DefaultMapper",
",",
"}",
"\n",
"}"
] | // Iter creates a new Iterx from gocql.Query using a default mapper. | [
"Iter",
"creates",
"a",
"new",
"Iterx",
"from",
"gocql",
".",
"Query",
"using",
"a",
"default",
"mapper",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L44-L49 | train |
scylladb/gocqlx | iterx.go | Get | func (iter *Iterx) Get(dest interface{}) error {
iter.scanAny(dest, false)
iter.Close()
return iter.checkErrAndNotFound()
} | go | func (iter *Iterx) Get(dest interface{}) error {
iter.scanAny(dest, false)
iter.Close()
return iter.checkErrAndNotFound()
} | [
"func",
"(",
"iter",
"*",
"Iterx",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"iter",
".",
"scanAny",
"(",
"dest",
",",
"false",
")",
"\n",
"iter",
".",
"Close",
"(",
")",
"\n\n",
"return",
"iter",
".",
"checkErrAndNotFound",
"(",
")",
"\n",
"}"
] | // Get scans first row into a destination and closes the iterator. If the
// destination type is a struct pointer, then StructScan will be used.
// If the destination is some other type, then the row must only have one column
// which can scan into that type.
//
// If no rows were selected, ErrNotFound is returned. | [
"Get",
"scans",
"first",
"row",
"into",
"a",
"destination",
"and",
"closes",
"the",
"iterator",
".",
"If",
"the",
"destination",
"type",
"is",
"a",
"struct",
"pointer",
"then",
"StructScan",
"will",
"be",
"used",
".",
"If",
"the",
"destination",
"is",
"some",
"other",
"type",
"then",
"the",
"row",
"must",
"only",
"have",
"one",
"column",
"which",
"can",
"scan",
"into",
"that",
"type",
".",
"If",
"no",
"rows",
"were",
"selected",
"ErrNotFound",
"is",
"returned",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L65-L70 | train |
scylladb/gocqlx | iterx.go | Select | func (iter *Iterx) Select(dest interface{}) error {
iter.scanAll(dest, false)
iter.Close()
return iter.err
} | go | func (iter *Iterx) Select(dest interface{}) error {
iter.scanAll(dest, false)
iter.Close()
return iter.err
} | [
"func",
"(",
"iter",
"*",
"Iterx",
")",
"Select",
"(",
"dest",
"interface",
"{",
"}",
")",
"error",
"{",
"iter",
".",
"scanAll",
"(",
"dest",
",",
"false",
")",
"\n",
"iter",
".",
"Close",
"(",
")",
"\n\n",
"return",
"iter",
".",
"err",
"\n",
"}"
] | // Select scans all rows into a destination, which must be a pointer to slice
// of any type and closes the iterator. If the destination slice type is
// a struct, then StructScan will be used on each row. If the destination is
// some other type, then each row must only have one column which can scan into
// that type.
//
// If no rows were selected, ErrNotFound is NOT returned. | [
"Select",
"scans",
"all",
"rows",
"into",
"a",
"destination",
"which",
"must",
"be",
"a",
"pointer",
"to",
"slice",
"of",
"any",
"type",
"and",
"closes",
"the",
"iterator",
".",
"If",
"the",
"destination",
"slice",
"type",
"is",
"a",
"struct",
"then",
"StructScan",
"will",
"be",
"used",
"on",
"each",
"row",
".",
"If",
"the",
"destination",
"is",
"some",
"other",
"type",
"then",
"each",
"row",
"must",
"only",
"have",
"one",
"column",
"which",
"can",
"scan",
"into",
"that",
"type",
".",
"If",
"no",
"rows",
"were",
"selected",
"ErrNotFound",
"is",
"NOT",
"returned",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/iterx.go#L115-L120 | train |
scylladb/gocqlx | queryx_wrap.go | SetSpeculativeExecutionPolicy | func (q *Queryx) SetSpeculativeExecutionPolicy(sp gocql.SpeculativeExecutionPolicy) *Queryx {
q.Query.SetSpeculativeExecutionPolicy(sp)
return q
} | go | func (q *Queryx) SetSpeculativeExecutionPolicy(sp gocql.SpeculativeExecutionPolicy) *Queryx {
q.Query.SetSpeculativeExecutionPolicy(sp)
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"SetSpeculativeExecutionPolicy",
"(",
"sp",
"gocql",
".",
"SpeculativeExecutionPolicy",
")",
"*",
"Queryx",
"{",
"q",
".",
"Query",
".",
"SetSpeculativeExecutionPolicy",
"(",
"sp",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // SetSpeculativeExecutionPolicy sets the execution policy. | [
"SetSpeculativeExecutionPolicy",
"sets",
"the",
"execution",
"policy",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx_wrap.go#L108-L111 | train |
scylladb/gocqlx | queryx_wrap.go | Bind | func (q *Queryx) Bind(v ...interface{}) *Queryx {
q.Query.Bind(v...)
return q
} | go | func (q *Queryx) Bind(v ...interface{}) *Queryx {
q.Query.Bind(v...)
return q
} | [
"func",
"(",
"q",
"*",
"Queryx",
")",
"Bind",
"(",
"v",
"...",
"interface",
"{",
"}",
")",
"*",
"Queryx",
"{",
"q",
".",
"Query",
".",
"Bind",
"(",
"v",
"...",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // Bind sets query arguments of query. This can also be used to rebind new query arguments
// to an existing query instance. | [
"Bind",
"sets",
"query",
"arguments",
"of",
"query",
".",
"This",
"can",
"also",
"be",
"used",
"to",
"rebind",
"new",
"query",
"arguments",
"to",
"an",
"existing",
"query",
"instance",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/queryx_wrap.go#L122-L125 | train |
scylladb/gocqlx | qb/cmp.go | Eq | func Eq(column string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(column),
}
} | go | func Eq(column string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(column),
}
} | [
"func",
"Eq",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"eq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Eq produces column=?. | [
"Eq",
"produces",
"column",
"=",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L61-L67 | train |
scylladb/gocqlx | qb/cmp.go | EqNamed | func EqNamed(column, name string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(name),
}
} | go | func EqNamed(column, name string) Cmp {
return Cmp{
op: eq,
column: column,
value: param(name),
}
} | [
"func",
"EqNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"eq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // EqNamed produces column=? with a custom parameter name. | [
"EqNamed",
"produces",
"column",
"=",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L70-L76 | train |
scylladb/gocqlx | qb/cmp.go | EqLit | func EqLit(column, literal string) Cmp {
return Cmp{
op: eq,
column: column,
value: lit(literal),
}
} | go | func EqLit(column, literal string) Cmp {
return Cmp{
op: eq,
column: column,
value: lit(literal),
}
} | [
"func",
"EqLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"eq",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // EqLit produces column=literal and does not add a parameter to the query. | [
"EqLit",
"produces",
"column",
"=",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L79-L85 | train |
scylladb/gocqlx | qb/cmp.go | Lt | func Lt(column string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(column),
}
} | go | func Lt(column string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(column),
}
} | [
"func",
"Lt",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"lt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Lt produces column<?. | [
"Lt",
"produces",
"column<?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L97-L103 | train |
scylladb/gocqlx | qb/cmp.go | LtNamed | func LtNamed(column, name string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(name),
}
} | go | func LtNamed(column, name string) Cmp {
return Cmp{
op: lt,
column: column,
value: param(name),
}
} | [
"func",
"LtNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"lt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // LtNamed produces column<? with a custom parameter name. | [
"LtNamed",
"produces",
"column<?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L106-L112 | train |
scylladb/gocqlx | qb/cmp.go | LtLit | func LtLit(column, literal string) Cmp {
return Cmp{
op: lt,
column: column,
value: lit(literal),
}
} | go | func LtLit(column, literal string) Cmp {
return Cmp{
op: lt,
column: column,
value: lit(literal),
}
} | [
"func",
"LtLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"lt",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // LtLit produces column<literal and does not add a parameter to the query. | [
"LtLit",
"produces",
"column<literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L115-L121 | train |
scylladb/gocqlx | qb/cmp.go | LtOrEq | func LtOrEq(column string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(column),
}
} | go | func LtOrEq(column string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(column),
}
} | [
"func",
"LtOrEq",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"leq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // LtOrEq produces column<=?. | [
"LtOrEq",
"produces",
"column<",
"=",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L133-L139 | train |
scylladb/gocqlx | qb/cmp.go | LtOrEqNamed | func LtOrEqNamed(column, name string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(name),
}
} | go | func LtOrEqNamed(column, name string) Cmp {
return Cmp{
op: leq,
column: column,
value: param(name),
}
} | [
"func",
"LtOrEqNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"leq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // LtOrEqNamed produces column<=? with a custom parameter name. | [
"LtOrEqNamed",
"produces",
"column<",
"=",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L142-L148 | train |
scylladb/gocqlx | qb/cmp.go | LtOrEqLit | func LtOrEqLit(column, literal string) Cmp {
return Cmp{
op: leq,
column: column,
value: lit(literal),
}
} | go | func LtOrEqLit(column, literal string) Cmp {
return Cmp{
op: leq,
column: column,
value: lit(literal),
}
} | [
"func",
"LtOrEqLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"leq",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // LtOrEqLit produces column<=literal and does not add a parameter to the query. | [
"LtOrEqLit",
"produces",
"column<",
"=",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L151-L157 | train |
scylladb/gocqlx | qb/cmp.go | Gt | func Gt(column string) Cmp {
return Cmp{
op: gt,
column: column,
value: param(column),
}
} | go | func Gt(column string) Cmp {
return Cmp{
op: gt,
column: column,
value: param(column),
}
} | [
"func",
"Gt",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"gt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Gt produces column>?. | [
"Gt",
"produces",
"column",
">",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L169-L175 | train |
scylladb/gocqlx | qb/cmp.go | GtNamed | func GtNamed(column, name string) Cmp {
return Cmp{
op: gt,
column: column,
value: param(name),
}
} | go | func GtNamed(column, name string) Cmp {
return Cmp{
op: gt,
column: column,
value: param(name),
}
} | [
"func",
"GtNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"gt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // GtNamed produces column>? with a custom parameter name. | [
"GtNamed",
"produces",
"column",
">",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L178-L184 | train |
scylladb/gocqlx | qb/cmp.go | GtLit | func GtLit(column, literal string) Cmp {
return Cmp{
op: gt,
column: column,
value: lit(literal),
}
} | go | func GtLit(column, literal string) Cmp {
return Cmp{
op: gt,
column: column,
value: lit(literal),
}
} | [
"func",
"GtLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"gt",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // GtLit produces column>literal and does not add a parameter to the query. | [
"GtLit",
"produces",
"column",
">",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L187-L193 | train |
scylladb/gocqlx | qb/cmp.go | GtOrEq | func GtOrEq(column string) Cmp {
return Cmp{
op: geq,
column: column,
value: param(column),
}
} | go | func GtOrEq(column string) Cmp {
return Cmp{
op: geq,
column: column,
value: param(column),
}
} | [
"func",
"GtOrEq",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"geq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // GtOrEq produces column>=?. | [
"GtOrEq",
"produces",
"column",
">",
"=",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L205-L211 | train |
scylladb/gocqlx | qb/cmp.go | GtOrEqNamed | func GtOrEqNamed(column, name string) Cmp {
return Cmp{
op: geq,
column: column,
value: param(name),
}
} | go | func GtOrEqNamed(column, name string) Cmp {
return Cmp{
op: geq,
column: column,
value: param(name),
}
} | [
"func",
"GtOrEqNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"geq",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // GtOrEqNamed produces column>=? with a custom parameter name. | [
"GtOrEqNamed",
"produces",
"column",
">",
"=",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L214-L220 | train |
scylladb/gocqlx | qb/cmp.go | GtOrEqLit | func GtOrEqLit(column, literal string) Cmp {
return Cmp{
op: geq,
column: column,
value: lit(literal),
}
} | go | func GtOrEqLit(column, literal string) Cmp {
return Cmp{
op: geq,
column: column,
value: lit(literal),
}
} | [
"func",
"GtOrEqLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"geq",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // GtOrEqLit produces column>=literal and does not add a parameter to the query. | [
"GtOrEqLit",
"produces",
"column",
">",
"=",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L223-L229 | train |
scylladb/gocqlx | qb/cmp.go | In | func In(column string) Cmp {
return Cmp{
op: in,
column: column,
value: param(column),
}
} | go | func In(column string) Cmp {
return Cmp{
op: in,
column: column,
value: param(column),
}
} | [
"func",
"In",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"in",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // In produces column IN ?. | [
"In",
"produces",
"column",
"IN",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L241-L247 | train |
scylladb/gocqlx | qb/cmp.go | InNamed | func InNamed(column, name string) Cmp {
return Cmp{
op: in,
column: column,
value: param(name),
}
} | go | func InNamed(column, name string) Cmp {
return Cmp{
op: in,
column: column,
value: param(name),
}
} | [
"func",
"InNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"in",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // InNamed produces column IN ? with a custom parameter name. | [
"InNamed",
"produces",
"column",
"IN",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L250-L256 | train |
scylladb/gocqlx | qb/cmp.go | InLit | func InLit(column, literal string) Cmp {
return Cmp{
op: in,
column: column,
value: lit(literal),
}
} | go | func InLit(column, literal string) Cmp {
return Cmp{
op: in,
column: column,
value: lit(literal),
}
} | [
"func",
"InLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"in",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // InLit produces column IN literal and does not add a parameter to the query. | [
"InLit",
"produces",
"column",
"IN",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L259-L265 | train |
scylladb/gocqlx | qb/cmp.go | Contains | func Contains(column string) Cmp {
return Cmp{
op: cnt,
column: column,
value: param(column),
}
} | go | func Contains(column string) Cmp {
return Cmp{
op: cnt,
column: column,
value: param(column),
}
} | [
"func",
"Contains",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"cnt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Contains produces column CONTAINS ?. | [
"Contains",
"produces",
"column",
"CONTAINS",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L268-L274 | train |
scylladb/gocqlx | qb/cmp.go | ContainsKey | func ContainsKey(column string) Cmp {
return Cmp{
op: cntKey,
column: column,
value: param(column),
}
} | go | func ContainsKey(column string) Cmp {
return Cmp{
op: cntKey,
column: column,
value: param(column),
}
} | [
"func",
"ContainsKey",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"cntKey",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // ContainsKey produces column CONTAINS KEY ?. | [
"ContainsKey",
"produces",
"column",
"CONTAINS",
"KEY",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L277-L283 | train |
scylladb/gocqlx | qb/cmp.go | ContainsNamed | func ContainsNamed(column, name string) Cmp {
return Cmp{
op: cnt,
column: column,
value: param(name),
}
} | go | func ContainsNamed(column, name string) Cmp {
return Cmp{
op: cnt,
column: column,
value: param(name),
}
} | [
"func",
"ContainsNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"cnt",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // ContainsNamed produces column CONTAINS ? with a custom parameter name. | [
"ContainsNamed",
"produces",
"column",
"CONTAINS",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L286-L292 | train |
scylladb/gocqlx | qb/cmp.go | ContainsKeyNamed | func ContainsKeyNamed(column, name string) Cmp {
return Cmp{
op: cntKey,
column: column,
value: param(name),
}
} | go | func ContainsKeyNamed(column, name string) Cmp {
return Cmp{
op: cntKey,
column: column,
value: param(name),
}
} | [
"func",
"ContainsKeyNamed",
"(",
"column",
",",
"name",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"cntKey",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
"\n",
"}"
] | // ContainsKeyNamed produces column CONTAINS KEY ? with a custom parameter name. | [
"ContainsKeyNamed",
"produces",
"column",
"CONTAINS",
"KEY",
"?",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L295-L301 | train |
scylladb/gocqlx | qb/cmp.go | ContainsLit | func ContainsLit(column, literal string) Cmp {
return Cmp{
op: cnt,
column: column,
value: lit(literal),
}
} | go | func ContainsLit(column, literal string) Cmp {
return Cmp{
op: cnt,
column: column,
value: lit(literal),
}
} | [
"func",
"ContainsLit",
"(",
"column",
",",
"literal",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"cnt",
",",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
"\n",
"}"
] | // ContainsLit produces column CONTAINS literal and does not add a parameter to the query. | [
"ContainsLit",
"produces",
"column",
"CONTAINS",
"literal",
"and",
"does",
"not",
"add",
"a",
"parameter",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L304-L310 | train |
scylladb/gocqlx | qb/cmp.go | Like | func Like(column string) Cmp {
return Cmp{
op: like,
column: column,
value: param(column),
}
} | go | func Like(column string) Cmp {
return Cmp{
op: like,
column: column,
value: param(column),
}
} | [
"func",
"Like",
"(",
"column",
"string",
")",
"Cmp",
"{",
"return",
"Cmp",
"{",
"op",
":",
"like",
",",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"column",
")",
",",
"}",
"\n",
"}"
] | // Like produces column LIKE ?. | [
"Like",
"produces",
"column",
"LIKE",
"?",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/cmp.go#L313-L319 | train |
scylladb/gocqlx | qb/select.go | From | func (b *SelectBuilder) From(table string) *SelectBuilder {
b.table = table
return b
} | go | func (b *SelectBuilder) From(table string) *SelectBuilder {
b.table = table
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"From",
"(",
"table",
"string",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"table",
"=",
"table",
"\n",
"return",
"b",
"\n",
"}"
] | // From sets the table to be selected from. | [
"From",
"sets",
"the",
"table",
"to",
"be",
"selected",
"from",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L111-L114 | train |
scylladb/gocqlx | qb/select.go | Columns | func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder {
b.columns = append(b.columns, columns...)
return b
} | go | func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder {
b.columns = append(b.columns, columns...)
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"Columns",
"(",
"columns",
"...",
"string",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"columns",
"=",
"append",
"(",
"b",
".",
"columns",
",",
"columns",
"...",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Columns adds result columns to the query. | [
"Columns",
"adds",
"result",
"columns",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L117-L120 | train |
scylladb/gocqlx | qb/select.go | Distinct | func (b *SelectBuilder) Distinct(columns ...string) *SelectBuilder {
b.distinct = append(b.distinct, columns...)
return b
} | go | func (b *SelectBuilder) Distinct(columns ...string) *SelectBuilder {
b.distinct = append(b.distinct, columns...)
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"Distinct",
"(",
"columns",
"...",
"string",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"distinct",
"=",
"append",
"(",
"b",
".",
"distinct",
",",
"columns",
"...",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Distinct sets DISTINCT clause on the query. | [
"Distinct",
"sets",
"DISTINCT",
"clause",
"on",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L128-L131 | train |
scylladb/gocqlx | qb/select.go | GroupBy | func (b *SelectBuilder) GroupBy(columns ...string) *SelectBuilder {
b.groupBy = append(b.groupBy, columns...)
return b
} | go | func (b *SelectBuilder) GroupBy(columns ...string) *SelectBuilder {
b.groupBy = append(b.groupBy, columns...)
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"GroupBy",
"(",
"columns",
"...",
"string",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"groupBy",
"=",
"append",
"(",
"b",
".",
"groupBy",
",",
"columns",
"...",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // GroupBy sets GROUP BY clause on the query. Columns must be a primary key,
// this will automatically add the the columns as first selectors. | [
"GroupBy",
"sets",
"GROUP",
"BY",
"clause",
"on",
"the",
"query",
".",
"Columns",
"must",
"be",
"a",
"primary",
"key",
"this",
"will",
"automatically",
"add",
"the",
"the",
"columns",
"as",
"first",
"selectors",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L142-L145 | train |
scylladb/gocqlx | qb/select.go | OrderBy | func (b *SelectBuilder) OrderBy(column string, o Order) *SelectBuilder {
b.orderBy = append(b.orderBy, column+" "+o.String())
return b
} | go | func (b *SelectBuilder) OrderBy(column string, o Order) *SelectBuilder {
b.orderBy = append(b.orderBy, column+" "+o.String())
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"OrderBy",
"(",
"column",
"string",
",",
"o",
"Order",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"orderBy",
"=",
"append",
"(",
"b",
".",
"orderBy",
",",
"column",
"+",
"\"",
"\"",
"+",
"o",
".",
"String",
"(",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // OrderBy sets ORDER BY clause on the query. | [
"OrderBy",
"sets",
"ORDER",
"BY",
"clause",
"on",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L148-L151 | train |
scylladb/gocqlx | qb/select.go | Limit | func (b *SelectBuilder) Limit(limit uint) *SelectBuilder {
b.limit = limit
return b
} | go | func (b *SelectBuilder) Limit(limit uint) *SelectBuilder {
b.limit = limit
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"Limit",
"(",
"limit",
"uint",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"limit",
"=",
"limit",
"\n",
"return",
"b",
"\n",
"}"
] | // Limit sets a LIMIT clause on the query. | [
"Limit",
"sets",
"a",
"LIMIT",
"clause",
"on",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L154-L157 | train |
scylladb/gocqlx | qb/select.go | LimitPerPartition | func (b *SelectBuilder) LimitPerPartition(limit uint) *SelectBuilder {
b.limitPerPartition = limit
return b
} | go | func (b *SelectBuilder) LimitPerPartition(limit uint) *SelectBuilder {
b.limitPerPartition = limit
return b
} | [
"func",
"(",
"b",
"*",
"SelectBuilder",
")",
"LimitPerPartition",
"(",
"limit",
"uint",
")",
"*",
"SelectBuilder",
"{",
"b",
".",
"limitPerPartition",
"=",
"limit",
"\n",
"return",
"b",
"\n",
"}"
] | // LimitPerPartition sets a PER PARTITION LIMIT clause on the query. | [
"LimitPerPartition",
"sets",
"a",
"PER",
"PARTITION",
"LIMIT",
"clause",
"on",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/select.go#L160-L163 | train |
scylladb/gocqlx | qb/func.go | Fn | func Fn(name string, paramNames ...string) *Func {
return &Func{
Name: name,
ParamNames: paramNames,
}
} | go | func Fn(name string, paramNames ...string) *Func {
return &Func{
Name: name,
ParamNames: paramNames,
}
} | [
"func",
"Fn",
"(",
"name",
"string",
",",
"paramNames",
"...",
"string",
")",
"*",
"Func",
"{",
"return",
"&",
"Func",
"{",
"Name",
":",
"name",
",",
"ParamNames",
":",
"paramNames",
",",
"}",
"\n",
"}"
] | // Fn creates Func. | [
"Fn",
"creates",
"Func",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/func.go#L31-L36 | train |
scylladb/gocqlx | migrate/migrate.go | List | func List(ctx context.Context, session *gocql.Session) ([]*Info, error) {
if err := ensureInfoTable(ctx, session); err != nil {
return nil, err
}
var v []*Info
err := gocqlx.Select(&v, session.Query(selectInfo).WithContext(ctx))
if err == gocql.ErrNotFound {
return nil, nil
}
sort.Slice(v, func(i, j int) bool {
return v[i].Name < v[j].Name
})
return v, err
} | go | func List(ctx context.Context, session *gocql.Session) ([]*Info, error) {
if err := ensureInfoTable(ctx, session); err != nil {
return nil, err
}
var v []*Info
err := gocqlx.Select(&v, session.Query(selectInfo).WithContext(ctx))
if err == gocql.ErrNotFound {
return nil, nil
}
sort.Slice(v, func(i, j int) bool {
return v[i].Name < v[j].Name
})
return v, err
} | [
"func",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"gocql",
".",
"Session",
")",
"(",
"[",
"]",
"*",
"Info",
",",
"error",
")",
"{",
"if",
"err",
":=",
"ensureInfoTable",
"(",
"ctx",
",",
"session",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"v",
"[",
"]",
"*",
"Info",
"\n",
"err",
":=",
"gocqlx",
".",
"Select",
"(",
"&",
"v",
",",
"session",
".",
"Query",
"(",
"selectInfo",
")",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"if",
"err",
"==",
"gocql",
".",
"ErrNotFound",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"sort",
".",
"Slice",
"(",
"v",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"v",
"[",
"i",
"]",
".",
"Name",
"<",
"v",
"[",
"j",
"]",
".",
"Name",
"\n",
"}",
")",
"\n\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // List provides a listing of applied migrations. | [
"List",
"provides",
"a",
"listing",
"of",
"applied",
"migrations",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/migrate/migrate.go#L47-L63 | train |
scylladb/gocqlx | migrate/migrate.go | Migrate | func Migrate(ctx context.Context, session *gocql.Session, dir string) error {
// get database migrations
dbm, err := List(ctx, session)
if err != nil {
return fmt.Errorf("failed to list migrations: %s", err)
}
// get file migrations
fm, err := filepath.Glob(filepath.Join(dir, "*.cql"))
if err != nil {
return fmt.Errorf("failed to list migrations in %q: %s", dir, err)
}
if len(fm) == 0 {
return fmt.Errorf("no migration files found in %q", dir)
}
sort.Strings(fm)
// verify migrations
if len(dbm) > len(fm) {
return fmt.Errorf("database is ahead of %q", dir)
}
for i := 0; i < len(dbm); i++ {
if dbm[i].Name != filepath.Base(fm[i]) {
fmt.Println(dbm[i].Name, filepath.Base(fm[i]), i)
return errors.New("inconsistent migrations")
}
c, err := fileChecksum(fm[i])
if err != nil {
return fmt.Errorf("failed to calculate checksum for %q: %s", fm[i], err)
}
if dbm[i].Checksum != c {
return fmt.Errorf("file %q was tempered with, expected md5 %s", fm[i], dbm[i].Checksum)
}
}
// apply migrations
if len(dbm) > 0 {
last := len(dbm) - 1
if err := applyMigration(ctx, session, fm[last], dbm[last].Done); err != nil {
return fmt.Errorf("failed to apply migration %q: %s", fm[last], err)
}
}
for i := len(dbm); i < len(fm); i++ {
if err := applyMigration(ctx, session, fm[i], 0); err != nil {
return fmt.Errorf("failed to apply migration %q: %s", fm[i], err)
}
}
return nil
} | go | func Migrate(ctx context.Context, session *gocql.Session, dir string) error {
// get database migrations
dbm, err := List(ctx, session)
if err != nil {
return fmt.Errorf("failed to list migrations: %s", err)
}
// get file migrations
fm, err := filepath.Glob(filepath.Join(dir, "*.cql"))
if err != nil {
return fmt.Errorf("failed to list migrations in %q: %s", dir, err)
}
if len(fm) == 0 {
return fmt.Errorf("no migration files found in %q", dir)
}
sort.Strings(fm)
// verify migrations
if len(dbm) > len(fm) {
return fmt.Errorf("database is ahead of %q", dir)
}
for i := 0; i < len(dbm); i++ {
if dbm[i].Name != filepath.Base(fm[i]) {
fmt.Println(dbm[i].Name, filepath.Base(fm[i]), i)
return errors.New("inconsistent migrations")
}
c, err := fileChecksum(fm[i])
if err != nil {
return fmt.Errorf("failed to calculate checksum for %q: %s", fm[i], err)
}
if dbm[i].Checksum != c {
return fmt.Errorf("file %q was tempered with, expected md5 %s", fm[i], dbm[i].Checksum)
}
}
// apply migrations
if len(dbm) > 0 {
last := len(dbm) - 1
if err := applyMigration(ctx, session, fm[last], dbm[last].Done); err != nil {
return fmt.Errorf("failed to apply migration %q: %s", fm[last], err)
}
}
for i := len(dbm); i < len(fm); i++ {
if err := applyMigration(ctx, session, fm[i], 0); err != nil {
return fmt.Errorf("failed to apply migration %q: %s", fm[i], err)
}
}
return nil
} | [
"func",
"Migrate",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"*",
"gocql",
".",
"Session",
",",
"dir",
"string",
")",
"error",
"{",
"// get database migrations",
"dbm",
",",
"err",
":=",
"List",
"(",
"ctx",
",",
"session",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// get file migrations",
"fm",
",",
"err",
":=",
"filepath",
".",
"Glob",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"fm",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"fm",
")",
"\n\n",
"// verify migrations",
"if",
"len",
"(",
"dbm",
")",
">",
"len",
"(",
"fm",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"dbm",
")",
";",
"i",
"++",
"{",
"if",
"dbm",
"[",
"i",
"]",
".",
"Name",
"!=",
"filepath",
".",
"Base",
"(",
"fm",
"[",
"i",
"]",
")",
"{",
"fmt",
".",
"Println",
"(",
"dbm",
"[",
"i",
"]",
".",
"Name",
",",
"filepath",
".",
"Base",
"(",
"fm",
"[",
"i",
"]",
")",
",",
"i",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
",",
"err",
":=",
"fileChecksum",
"(",
"fm",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fm",
"[",
"i",
"]",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"dbm",
"[",
"i",
"]",
".",
"Checksum",
"!=",
"c",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fm",
"[",
"i",
"]",
",",
"dbm",
"[",
"i",
"]",
".",
"Checksum",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// apply migrations",
"if",
"len",
"(",
"dbm",
")",
">",
"0",
"{",
"last",
":=",
"len",
"(",
"dbm",
")",
"-",
"1",
"\n",
"if",
"err",
":=",
"applyMigration",
"(",
"ctx",
",",
"session",
",",
"fm",
"[",
"last",
"]",
",",
"dbm",
"[",
"last",
"]",
".",
"Done",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fm",
"[",
"last",
"]",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"len",
"(",
"dbm",
")",
";",
"i",
"<",
"len",
"(",
"fm",
")",
";",
"i",
"++",
"{",
"if",
"err",
":=",
"applyMigration",
"(",
"ctx",
",",
"session",
",",
"fm",
"[",
"i",
"]",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fm",
"[",
"i",
"]",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Migrate reads the cql files from a directory and applies required migrations. | [
"Migrate",
"reads",
"the",
"cql",
"files",
"from",
"a",
"directory",
"and",
"applies",
"required",
"migrations",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/migrate/migrate.go#L70-L121 | train |
scylladb/gocqlx | table/table.go | New | func New(m Metadata) *Table {
t := &Table{
metadata: m,
}
// prepare primary and partition key comparators
t.primaryKeyCmp = make([]qb.Cmp, 0, len(m.PartKey)+len(m.SortKey))
for _, k := range m.PartKey {
t.primaryKeyCmp = append(t.primaryKeyCmp, qb.Eq(k))
}
for _, k := range m.SortKey {
t.primaryKeyCmp = append(t.primaryKeyCmp, qb.Eq(k))
}
t.partKeyCmp = t.primaryKeyCmp[:len(t.metadata.PartKey)]
// prepare get stmt
t.get.stmt, t.get.names = qb.Select(m.Name).Where(t.primaryKeyCmp...).ToCql()
// prepare select stmt
t.sel.stmt, t.sel.names = qb.Select(m.Name).Where(t.partKeyCmp...).ToCql()
// prepare insert stmt
t.insert.stmt, t.insert.names = qb.Insert(m.Name).Columns(m.Columns...).ToCql()
return t
} | go | func New(m Metadata) *Table {
t := &Table{
metadata: m,
}
// prepare primary and partition key comparators
t.primaryKeyCmp = make([]qb.Cmp, 0, len(m.PartKey)+len(m.SortKey))
for _, k := range m.PartKey {
t.primaryKeyCmp = append(t.primaryKeyCmp, qb.Eq(k))
}
for _, k := range m.SortKey {
t.primaryKeyCmp = append(t.primaryKeyCmp, qb.Eq(k))
}
t.partKeyCmp = t.primaryKeyCmp[:len(t.metadata.PartKey)]
// prepare get stmt
t.get.stmt, t.get.names = qb.Select(m.Name).Where(t.primaryKeyCmp...).ToCql()
// prepare select stmt
t.sel.stmt, t.sel.names = qb.Select(m.Name).Where(t.partKeyCmp...).ToCql()
// prepare insert stmt
t.insert.stmt, t.insert.names = qb.Insert(m.Name).Columns(m.Columns...).ToCql()
return t
} | [
"func",
"New",
"(",
"m",
"Metadata",
")",
"*",
"Table",
"{",
"t",
":=",
"&",
"Table",
"{",
"metadata",
":",
"m",
",",
"}",
"\n\n",
"// prepare primary and partition key comparators",
"t",
".",
"primaryKeyCmp",
"=",
"make",
"(",
"[",
"]",
"qb",
".",
"Cmp",
",",
"0",
",",
"len",
"(",
"m",
".",
"PartKey",
")",
"+",
"len",
"(",
"m",
".",
"SortKey",
")",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"m",
".",
"PartKey",
"{",
"t",
".",
"primaryKeyCmp",
"=",
"append",
"(",
"t",
".",
"primaryKeyCmp",
",",
"qb",
".",
"Eq",
"(",
"k",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"m",
".",
"SortKey",
"{",
"t",
".",
"primaryKeyCmp",
"=",
"append",
"(",
"t",
".",
"primaryKeyCmp",
",",
"qb",
".",
"Eq",
"(",
"k",
")",
")",
"\n",
"}",
"\n",
"t",
".",
"partKeyCmp",
"=",
"t",
".",
"primaryKeyCmp",
"[",
":",
"len",
"(",
"t",
".",
"metadata",
".",
"PartKey",
")",
"]",
"\n\n",
"// prepare get stmt",
"t",
".",
"get",
".",
"stmt",
",",
"t",
".",
"get",
".",
"names",
"=",
"qb",
".",
"Select",
"(",
"m",
".",
"Name",
")",
".",
"Where",
"(",
"t",
".",
"primaryKeyCmp",
"...",
")",
".",
"ToCql",
"(",
")",
"\n",
"// prepare select stmt",
"t",
".",
"sel",
".",
"stmt",
",",
"t",
".",
"sel",
".",
"names",
"=",
"qb",
".",
"Select",
"(",
"m",
".",
"Name",
")",
".",
"Where",
"(",
"t",
".",
"partKeyCmp",
"...",
")",
".",
"ToCql",
"(",
")",
"\n",
"// prepare insert stmt",
"t",
".",
"insert",
".",
"stmt",
",",
"t",
".",
"insert",
".",
"names",
"=",
"qb",
".",
"Insert",
"(",
"m",
".",
"Name",
")",
".",
"Columns",
"(",
"m",
".",
"Columns",
"...",
")",
".",
"ToCql",
"(",
")",
"\n\n",
"return",
"t",
"\n",
"}"
] | // New creates new Table based on table schema read from Metadata. | [
"New",
"creates",
"new",
"Table",
"based",
"on",
"table",
"schema",
"read",
"from",
"Metadata",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L35-L58 | train |
scylladb/gocqlx | table/table.go | Get | func (t *Table) Get(columns ...string) (stmt string, names []string) {
if len(columns) == 0 {
return t.get.stmt, t.get.names
}
return qb.Select(t.metadata.Name).
Columns(columns...).
Where(t.primaryKeyCmp...).
ToCql()
} | go | func (t *Table) Get(columns ...string) (stmt string, names []string) {
if len(columns) == 0 {
return t.get.stmt, t.get.names
}
return qb.Select(t.metadata.Name).
Columns(columns...).
Where(t.primaryKeyCmp...).
ToCql()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Get",
"(",
"columns",
"...",
"string",
")",
"(",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"{",
"if",
"len",
"(",
"columns",
")",
"==",
"0",
"{",
"return",
"t",
".",
"get",
".",
"stmt",
",",
"t",
".",
"get",
".",
"names",
"\n",
"}",
"\n\n",
"return",
"qb",
".",
"Select",
"(",
"t",
".",
"metadata",
".",
"Name",
")",
".",
"Columns",
"(",
"columns",
"...",
")",
".",
"Where",
"(",
"t",
".",
"primaryKeyCmp",
"...",
")",
".",
"ToCql",
"(",
")",
"\n",
"}"
] | // Get returns select by primary key statement. | [
"Get",
"returns",
"select",
"by",
"primary",
"key",
"statement",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L71-L80 | train |
scylladb/gocqlx | table/table.go | Select | func (t *Table) Select(columns ...string) (stmt string, names []string) {
if len(columns) == 0 {
return t.sel.stmt, t.sel.names
}
return qb.Select(t.metadata.Name).
Columns(columns...).
Where(t.primaryKeyCmp[0:len(t.metadata.PartKey)]...).
ToCql()
} | go | func (t *Table) Select(columns ...string) (stmt string, names []string) {
if len(columns) == 0 {
return t.sel.stmt, t.sel.names
}
return qb.Select(t.metadata.Name).
Columns(columns...).
Where(t.primaryKeyCmp[0:len(t.metadata.PartKey)]...).
ToCql()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Select",
"(",
"columns",
"...",
"string",
")",
"(",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"{",
"if",
"len",
"(",
"columns",
")",
"==",
"0",
"{",
"return",
"t",
".",
"sel",
".",
"stmt",
",",
"t",
".",
"sel",
".",
"names",
"\n",
"}",
"\n\n",
"return",
"qb",
".",
"Select",
"(",
"t",
".",
"metadata",
".",
"Name",
")",
".",
"Columns",
"(",
"columns",
"...",
")",
".",
"Where",
"(",
"t",
".",
"primaryKeyCmp",
"[",
"0",
":",
"len",
"(",
"t",
".",
"metadata",
".",
"PartKey",
")",
"]",
"...",
")",
".",
"ToCql",
"(",
")",
"\n",
"}"
] | // Select returns select by partition key statement. | [
"Select",
"returns",
"select",
"by",
"partition",
"key",
"statement",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L83-L92 | train |
scylladb/gocqlx | table/table.go | SelectBuilder | func (t *Table) SelectBuilder(columns ...string) *qb.SelectBuilder {
return qb.Select(t.metadata.Name).Columns(columns...).Where(t.partKeyCmp...)
} | go | func (t *Table) SelectBuilder(columns ...string) *qb.SelectBuilder {
return qb.Select(t.metadata.Name).Columns(columns...).Where(t.partKeyCmp...)
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"SelectBuilder",
"(",
"columns",
"...",
"string",
")",
"*",
"qb",
".",
"SelectBuilder",
"{",
"return",
"qb",
".",
"Select",
"(",
"t",
".",
"metadata",
".",
"Name",
")",
".",
"Columns",
"(",
"columns",
"...",
")",
".",
"Where",
"(",
"t",
".",
"partKeyCmp",
"...",
")",
"\n",
"}"
] | // SelectBuilder returns a builder initialised to select by partition key
// statement. | [
"SelectBuilder",
"returns",
"a",
"builder",
"initialised",
"to",
"select",
"by",
"partition",
"key",
"statement",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L96-L98 | train |
scylladb/gocqlx | table/table.go | Insert | func (t *Table) Insert() (stmt string, names []string) {
return t.insert.stmt, t.insert.names
} | go | func (t *Table) Insert() (stmt string, names []string) {
return t.insert.stmt, t.insert.names
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Insert",
"(",
")",
"(",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"{",
"return",
"t",
".",
"insert",
".",
"stmt",
",",
"t",
".",
"insert",
".",
"names",
"\n",
"}"
] | // Insert returns insert all columns statement. | [
"Insert",
"returns",
"insert",
"all",
"columns",
"statement",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L101-L103 | train |
scylladb/gocqlx | table/table.go | Update | func (t *Table) Update(columns ...string) (stmt string, names []string) {
return qb.Update(t.metadata.Name).Set(columns...).Where(t.primaryKeyCmp...).ToCql()
} | go | func (t *Table) Update(columns ...string) (stmt string, names []string) {
return qb.Update(t.metadata.Name).Set(columns...).Where(t.primaryKeyCmp...).ToCql()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Update",
"(",
"columns",
"...",
"string",
")",
"(",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"{",
"return",
"qb",
".",
"Update",
"(",
"t",
".",
"metadata",
".",
"Name",
")",
".",
"Set",
"(",
"columns",
"...",
")",
".",
"Where",
"(",
"t",
".",
"primaryKeyCmp",
"...",
")",
".",
"ToCql",
"(",
")",
"\n",
"}"
] | // Update returns update by primary key statement. | [
"Update",
"returns",
"update",
"by",
"primary",
"key",
"statement",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L106-L108 | train |
scylladb/gocqlx | table/table.go | Delete | func (t *Table) Delete(columns ...string) (stmt string, names []string) {
return qb.Delete(t.metadata.Name).Columns(columns...).Where(t.primaryKeyCmp...).ToCql()
} | go | func (t *Table) Delete(columns ...string) (stmt string, names []string) {
return qb.Delete(t.metadata.Name).Columns(columns...).Where(t.primaryKeyCmp...).ToCql()
} | [
"func",
"(",
"t",
"*",
"Table",
")",
"Delete",
"(",
"columns",
"...",
"string",
")",
"(",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"{",
"return",
"qb",
".",
"Delete",
"(",
"t",
".",
"metadata",
".",
"Name",
")",
".",
"Columns",
"(",
"columns",
"...",
")",
".",
"Where",
"(",
"t",
".",
"primaryKeyCmp",
"...",
")",
".",
"ToCql",
"(",
")",
"\n",
"}"
] | // Delete returns delete by primary key statement. | [
"Delete",
"returns",
"delete",
"by",
"primary",
"key",
"statement",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/table/table.go#L111-L113 | train |
scylladb/gocqlx | qb/delete.go | From | func (b *DeleteBuilder) From(table string) *DeleteBuilder {
b.table = table
return b
} | go | func (b *DeleteBuilder) From(table string) *DeleteBuilder {
b.table = table
return b
} | [
"func",
"(",
"b",
"*",
"DeleteBuilder",
")",
"From",
"(",
"table",
"string",
")",
"*",
"DeleteBuilder",
"{",
"b",
".",
"table",
"=",
"table",
"\n",
"return",
"b",
"\n",
"}"
] | // From sets the table to be deleted from. | [
"From",
"sets",
"the",
"table",
"to",
"be",
"deleted",
"from",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/delete.go#L58-L61 | train |
scylladb/gocqlx | qb/delete.go | Columns | func (b *DeleteBuilder) Columns(columns ...string) *DeleteBuilder {
b.columns = append(b.columns, columns...)
return b
} | go | func (b *DeleteBuilder) Columns(columns ...string) *DeleteBuilder {
b.columns = append(b.columns, columns...)
return b
} | [
"func",
"(",
"b",
"*",
"DeleteBuilder",
")",
"Columns",
"(",
"columns",
"...",
"string",
")",
"*",
"DeleteBuilder",
"{",
"b",
".",
"columns",
"=",
"append",
"(",
"b",
".",
"columns",
",",
"columns",
"...",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Columns adds delete columns to the query. | [
"Columns",
"adds",
"delete",
"columns",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/delete.go#L64-L67 | train |
scylladb/gocqlx | gocqlx.go | structOnlyError | func structOnlyError(t reflect.Type) error {
isStruct := t.Kind() == reflect.Struct
isScanner := reflect.PtrTo(t).Implements(_unmarshallerInterface)
if !isStruct {
return fmt.Errorf("expected %s but got %s", reflect.Struct, t.Kind())
}
if isScanner {
return fmt.Errorf("structscan expects a struct dest but the provided struct type %s implements unmarshaler", t.Name())
}
return fmt.Errorf("expected a struct, but struct %s has no exported fields", t.Name())
} | go | func structOnlyError(t reflect.Type) error {
isStruct := t.Kind() == reflect.Struct
isScanner := reflect.PtrTo(t).Implements(_unmarshallerInterface)
if !isStruct {
return fmt.Errorf("expected %s but got %s", reflect.Struct, t.Kind())
}
if isScanner {
return fmt.Errorf("structscan expects a struct dest but the provided struct type %s implements unmarshaler", t.Name())
}
return fmt.Errorf("expected a struct, but struct %s has no exported fields", t.Name())
} | [
"func",
"structOnlyError",
"(",
"t",
"reflect",
".",
"Type",
")",
"error",
"{",
"isStruct",
":=",
"t",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"\n",
"isScanner",
":=",
"reflect",
".",
"PtrTo",
"(",
"t",
")",
".",
"Implements",
"(",
"_unmarshallerInterface",
")",
"\n",
"if",
"!",
"isStruct",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"reflect",
".",
"Struct",
",",
"t",
".",
"Kind",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"isScanner",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"t",
".",
"Name",
"(",
")",
")",
"\n",
"}"
] | // structOnlyError returns an error appropriate for type when a non-scannable
// struct is expected but something else is given | [
"structOnlyError",
"returns",
"an",
"error",
"appropriate",
"for",
"type",
"when",
"a",
"non",
"-",
"scannable",
"struct",
"is",
"expected",
"but",
"something",
"else",
"is",
"given"
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/gocqlx.go#L18-L28 | train |
scylladb/gocqlx | gocqlx.go | fieldsByTraversal | func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
v = reflect.Indirect(v)
if v.Kind() != reflect.Struct {
return errors.New("argument not a struct")
}
for i, traversal := range traversals {
if len(traversal) == 0 {
continue
}
f := reflectx.FieldByIndexes(v, traversal)
if ptrs {
values[i] = f.Addr().Interface()
} else {
values[i] = f.Interface()
}
}
return nil
} | go | func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
v = reflect.Indirect(v)
if v.Kind() != reflect.Struct {
return errors.New("argument not a struct")
}
for i, traversal := range traversals {
if len(traversal) == 0 {
continue
}
f := reflectx.FieldByIndexes(v, traversal)
if ptrs {
values[i] = f.Addr().Interface()
} else {
values[i] = f.Interface()
}
}
return nil
} | [
"func",
"fieldsByTraversal",
"(",
"v",
"reflect",
".",
"Value",
",",
"traversals",
"[",
"]",
"[",
"]",
"int",
",",
"values",
"[",
"]",
"interface",
"{",
"}",
",",
"ptrs",
"bool",
")",
"error",
"{",
"v",
"=",
"reflect",
".",
"Indirect",
"(",
"v",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Struct",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"traversal",
":=",
"range",
"traversals",
"{",
"if",
"len",
"(",
"traversal",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"f",
":=",
"reflectx",
".",
"FieldByIndexes",
"(",
"v",
",",
"traversal",
")",
"\n",
"if",
"ptrs",
"{",
"values",
"[",
"i",
"]",
"=",
"f",
".",
"Addr",
"(",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"else",
"{",
"values",
"[",
"i",
"]",
"=",
"f",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // fieldsByName fills a values interface with fields from the passed value based
// on the traversals in int. If ptrs is true, return addresses instead of values.
// We write this instead of using FieldsByName to save allocations and map lookups
// when iterating over many rows. Empty traversals will get an interface pointer.
// Because of the necessity of requesting ptrs or values, it's considered a bit too
// specialized for inclusion in reflectx itself. | [
"fieldsByName",
"fills",
"a",
"values",
"interface",
"with",
"fields",
"from",
"the",
"passed",
"value",
"based",
"on",
"the",
"traversals",
"in",
"int",
".",
"If",
"ptrs",
"is",
"true",
"return",
"addresses",
"instead",
"of",
"values",
".",
"We",
"write",
"this",
"instead",
"of",
"using",
"FieldsByName",
"to",
"save",
"allocations",
"and",
"map",
"lookups",
"when",
"iterating",
"over",
"many",
"rows",
".",
"Empty",
"traversals",
"will",
"get",
"an",
"interface",
"pointer",
".",
"Because",
"of",
"the",
"necessity",
"of",
"requesting",
"ptrs",
"or",
"values",
"it",
"s",
"considered",
"a",
"bit",
"too",
"specialized",
"for",
"inclusion",
"in",
"reflectx",
"itself",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/gocqlx.go#L68-L86 | train |
scylladb/gocqlx | qb/insert.go | Into | func (b *InsertBuilder) Into(table string) *InsertBuilder {
b.table = table
return b
} | go | func (b *InsertBuilder) Into(table string) *InsertBuilder {
b.table = table
return b
} | [
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"Into",
"(",
"table",
"string",
")",
"*",
"InsertBuilder",
"{",
"b",
".",
"table",
"=",
"table",
"\n",
"return",
"b",
"\n",
"}"
] | // Into sets the INTO clause of the query. | [
"Into",
"sets",
"the",
"INTO",
"clause",
"of",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/insert.go#L74-L77 | train |
scylladb/gocqlx | qb/insert.go | Columns | func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
for _, c := range columns {
b.columns = append(b.columns, initializer{
column: c,
value: param(c),
})
}
return b
} | go | func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
for _, c := range columns {
b.columns = append(b.columns, initializer{
column: c,
value: param(c),
})
}
return b
} | [
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"Columns",
"(",
"columns",
"...",
"string",
")",
"*",
"InsertBuilder",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"columns",
"{",
"b",
".",
"columns",
"=",
"append",
"(",
"b",
".",
"columns",
",",
"initializer",
"{",
"column",
":",
"c",
",",
"value",
":",
"param",
"(",
"c",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // Columns adds insert columns to the query. | [
"Columns",
"adds",
"insert",
"columns",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/insert.go#L80-L88 | train |
scylladb/gocqlx | qb/insert.go | NamedColumn | func (b *InsertBuilder) NamedColumn(column, name string) *InsertBuilder {
b.columns = append(b.columns, initializer{
column: column,
value: param(name),
})
return b
} | go | func (b *InsertBuilder) NamedColumn(column, name string) *InsertBuilder {
b.columns = append(b.columns, initializer{
column: column,
value: param(name),
})
return b
} | [
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"NamedColumn",
"(",
"column",
",",
"name",
"string",
")",
"*",
"InsertBuilder",
"{",
"b",
".",
"columns",
"=",
"append",
"(",
"b",
".",
"columns",
",",
"initializer",
"{",
"column",
":",
"column",
",",
"value",
":",
"param",
"(",
"name",
")",
",",
"}",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // NamedColumn adds an insert column with a custom parameter name. | [
"NamedColumn",
"adds",
"an",
"insert",
"column",
"with",
"a",
"custom",
"parameter",
"name",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/insert.go#L91-L97 | train |
scylladb/gocqlx | qb/insert.go | LitColumn | func (b *InsertBuilder) LitColumn(column, literal string) *InsertBuilder {
b.columns = append(b.columns, initializer{
column: column,
value: lit(literal),
})
return b
} | go | func (b *InsertBuilder) LitColumn(column, literal string) *InsertBuilder {
b.columns = append(b.columns, initializer{
column: column,
value: lit(literal),
})
return b
} | [
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"LitColumn",
"(",
"column",
",",
"literal",
"string",
")",
"*",
"InsertBuilder",
"{",
"b",
".",
"columns",
"=",
"append",
"(",
"b",
".",
"columns",
",",
"initializer",
"{",
"column",
":",
"column",
",",
"value",
":",
"lit",
"(",
"literal",
")",
",",
"}",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // LitColumn adds an insert column with a literal value to the query. | [
"LitColumn",
"adds",
"an",
"insert",
"column",
"with",
"a",
"literal",
"value",
"to",
"the",
"query",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/insert.go#L100-L106 | train |
scylladb/gocqlx | qb/insert.go | FuncColumn | func (b *InsertBuilder) FuncColumn(column string, fn *Func) *InsertBuilder {
b.columns = append(b.columns, initializer{
column: column,
value: fn,
})
return b
} | go | func (b *InsertBuilder) FuncColumn(column string, fn *Func) *InsertBuilder {
b.columns = append(b.columns, initializer{
column: column,
value: fn,
})
return b
} | [
"func",
"(",
"b",
"*",
"InsertBuilder",
")",
"FuncColumn",
"(",
"column",
"string",
",",
"fn",
"*",
"Func",
")",
"*",
"InsertBuilder",
"{",
"b",
".",
"columns",
"=",
"append",
"(",
"b",
".",
"columns",
",",
"initializer",
"{",
"column",
":",
"column",
",",
"value",
":",
"fn",
",",
"}",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // FuncColumn adds an insert column initialized by evaluating a CQL function. | [
"FuncColumn",
"adds",
"an",
"insert",
"column",
"initialized",
"by",
"evaluating",
"a",
"CQL",
"function",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/insert.go#L109-L115 | train |
scylladb/gocqlx | qb/batch.go | Add | func (b *BatchBuilder) Add(builder Builder) *BatchBuilder {
return b.AddStmt(builder.ToCql())
} | go | func (b *BatchBuilder) Add(builder Builder) *BatchBuilder {
return b.AddStmt(builder.ToCql())
} | [
"func",
"(",
"b",
"*",
"BatchBuilder",
")",
"Add",
"(",
"builder",
"Builder",
")",
"*",
"BatchBuilder",
"{",
"return",
"b",
".",
"AddStmt",
"(",
"builder",
".",
"ToCql",
"(",
")",
")",
"\n",
"}"
] | // Add builds the builder and adds the statement to the batch. | [
"Add",
"builds",
"the",
"builder",
"and",
"adds",
"the",
"statement",
"to",
"the",
"batch",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/batch.go#L59-L61 | train |
scylladb/gocqlx | qb/batch.go | AddStmt | func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder {
b.stmts = append(b.stmts, stmt)
b.names = append(b.names, names...)
return b
} | go | func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder {
b.stmts = append(b.stmts, stmt)
b.names = append(b.names, names...)
return b
} | [
"func",
"(",
"b",
"*",
"BatchBuilder",
")",
"AddStmt",
"(",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"*",
"BatchBuilder",
"{",
"b",
".",
"stmts",
"=",
"append",
"(",
"b",
".",
"stmts",
",",
"stmt",
")",
"\n",
"b",
".",
"names",
"=",
"append",
"(",
"b",
".",
"names",
",",
"names",
"...",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // AddStmt adds statement to the batch. | [
"AddStmt",
"adds",
"statement",
"to",
"the",
"batch",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/batch.go#L64-L68 | train |
scylladb/gocqlx | qb/batch.go | AddWithPrefix | func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder {
stmt, names := builder.ToCql()
return b.AddStmtWithPrefix(prefix, stmt, names)
} | go | func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder {
stmt, names := builder.ToCql()
return b.AddStmtWithPrefix(prefix, stmt, names)
} | [
"func",
"(",
"b",
"*",
"BatchBuilder",
")",
"AddWithPrefix",
"(",
"prefix",
"string",
",",
"builder",
"Builder",
")",
"*",
"BatchBuilder",
"{",
"stmt",
",",
"names",
":=",
"builder",
".",
"ToCql",
"(",
")",
"\n",
"return",
"b",
".",
"AddStmtWithPrefix",
"(",
"prefix",
",",
"stmt",
",",
"names",
")",
"\n",
"}"
] | // AddWithPrefix builds the builder and adds the statement to the batch. Names
// are prefixed with the prefix + ".". | [
"AddWithPrefix",
"builds",
"the",
"builder",
"and",
"adds",
"the",
"statement",
"to",
"the",
"batch",
".",
"Names",
"are",
"prefixed",
"with",
"the",
"prefix",
"+",
".",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/batch.go#L72-L75 | train |
scylladb/gocqlx | qb/batch.go | AddStmtWithPrefix | func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder {
b.stmts = append(b.stmts, stmt)
for _, name := range names {
if prefix != "" {
name = fmt.Sprint(prefix, ".", name)
}
b.names = append(b.names, name)
}
return b
} | go | func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder {
b.stmts = append(b.stmts, stmt)
for _, name := range names {
if prefix != "" {
name = fmt.Sprint(prefix, ".", name)
}
b.names = append(b.names, name)
}
return b
} | [
"func",
"(",
"b",
"*",
"BatchBuilder",
")",
"AddStmtWithPrefix",
"(",
"prefix",
"string",
",",
"stmt",
"string",
",",
"names",
"[",
"]",
"string",
")",
"*",
"BatchBuilder",
"{",
"b",
".",
"stmts",
"=",
"append",
"(",
"b",
".",
"stmts",
",",
"stmt",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"if",
"prefix",
"!=",
"\"",
"\"",
"{",
"name",
"=",
"fmt",
".",
"Sprint",
"(",
"prefix",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"b",
".",
"names",
"=",
"append",
"(",
"b",
".",
"names",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // AddStmtWithPrefix adds statement to the batch. Names are prefixed with
// the prefix + ".". | [
"AddStmtWithPrefix",
"adds",
"statement",
"to",
"the",
"batch",
".",
"Names",
"are",
"prefixed",
"with",
"the",
"prefix",
"+",
".",
"."
] | 3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5 | https://github.com/scylladb/gocqlx/blob/3a6a3da0c7b34883b12cb1730c936b2ebd3d04a5/qb/batch.go#L79-L88 | train |
cespare/reflex | backlog.go | Add | func (b *UnifiedBacklog) Add(path string) {
if b.empty {
b.s = path
b.empty = false
}
} | go | func (b *UnifiedBacklog) Add(path string) {
if b.empty {
b.s = path
b.empty = false
}
} | [
"func",
"(",
"b",
"*",
"UnifiedBacklog",
")",
"Add",
"(",
"path",
"string",
")",
"{",
"if",
"b",
".",
"empty",
"{",
"b",
".",
"s",
"=",
"path",
"\n",
"b",
".",
"empty",
"=",
"false",
"\n",
"}",
"\n",
"}"
] | // Add adds path to b if there is not a path there currently.
// Otherwise it discards it. | [
"Add",
"adds",
"path",
"to",
"b",
"if",
"there",
"is",
"not",
"a",
"path",
"there",
"currently",
".",
"Otherwise",
"it",
"discards",
"it",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/backlog.go#L30-L35 | train |
cespare/reflex | backlog.go | RemoveOne | func (b *UnifiedBacklog) RemoveOne() bool {
if b.empty {
panic("RemoveOne() called on empty backlog")
}
b.empty = true
b.s = ""
return true
} | go | func (b *UnifiedBacklog) RemoveOne() bool {
if b.empty {
panic("RemoveOne() called on empty backlog")
}
b.empty = true
b.s = ""
return true
} | [
"func",
"(",
"b",
"*",
"UnifiedBacklog",
")",
"RemoveOne",
"(",
")",
"bool",
"{",
"if",
"b",
".",
"empty",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"b",
".",
"empty",
"=",
"true",
"\n",
"b",
".",
"s",
"=",
"\"",
"\"",
"\n",
"return",
"true",
"\n",
"}"
] | // RemoveOne removes the path in b. | [
"RemoveOne",
"removes",
"the",
"path",
"in",
"b",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/backlog.go#L46-L53 | train |
cespare/reflex | backlog.go | Add | func (b *UniqueFilesBacklog) Add(path string) {
defer func() { b.empty = false }()
if b.empty {
b.next = path
return
}
if path == b.next {
return
}
b.rest[path] = struct{}{}
} | go | func (b *UniqueFilesBacklog) Add(path string) {
defer func() { b.empty = false }()
if b.empty {
b.next = path
return
}
if path == b.next {
return
}
b.rest[path] = struct{}{}
} | [
"func",
"(",
"b",
"*",
"UniqueFilesBacklog",
")",
"Add",
"(",
"path",
"string",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"b",
".",
"empty",
"=",
"false",
"}",
"(",
")",
"\n",
"if",
"b",
".",
"empty",
"{",
"b",
".",
"next",
"=",
"path",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"path",
"==",
"b",
".",
"next",
"{",
"return",
"\n",
"}",
"\n",
"b",
".",
"rest",
"[",
"path",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}"
] | // Add adds path to the set of files in b. | [
"Add",
"adds",
"path",
"to",
"the",
"set",
"of",
"files",
"in",
"b",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/backlog.go#L71-L81 | train |
cespare/reflex | config.go | ReadConfigs | func ReadConfigs(path string) ([]*Config, error) {
var r io.Reader
name := path
if path == "-" {
r = os.Stdin
name = "standard input"
} else {
f, err := os.Open(flagConf)
if err != nil {
return nil, err
}
defer f.Close()
r = f
}
return readConfigsFromReader(r, name)
} | go | func ReadConfigs(path string) ([]*Config, error) {
var r io.Reader
name := path
if path == "-" {
r = os.Stdin
name = "standard input"
} else {
f, err := os.Open(flagConf)
if err != nil {
return nil, err
}
defer f.Close()
r = f
}
return readConfigsFromReader(r, name)
} | [
"func",
"ReadConfigs",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"*",
"Config",
",",
"error",
")",
"{",
"var",
"r",
"io",
".",
"Reader",
"\n",
"name",
":=",
"path",
"\n",
"if",
"path",
"==",
"\"",
"\"",
"{",
"r",
"=",
"os",
".",
"Stdin",
"\n",
"name",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"flagConf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"r",
"=",
"f",
"\n",
"}",
"\n",
"return",
"readConfigsFromReader",
"(",
"r",
",",
"name",
")",
"\n",
"}"
] | // ReadConfigs reads configurations from either a file or, as a special case,
// stdin if "-" is given for path. | [
"ReadConfigs",
"reads",
"configurations",
"from",
"either",
"a",
"file",
"or",
"as",
"a",
"special",
"case",
"stdin",
"if",
"-",
"is",
"given",
"for",
"path",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/config.go#L60-L75 | train |
cespare/reflex | watch.go | watch | func watch(root string, watcher *fsnotify.Watcher, names chan<- string, done chan<- error, reflexes []*Reflex) {
if err := filepath.Walk(root, walker(watcher, reflexes)); err != nil {
infoPrintf(-1, "Error while walking path %s: %s", root, err)
}
for {
select {
case e := <-watcher.Events:
if verbose {
infoPrintln(-1, "fsnotify event:", e)
}
stat, err := os.Stat(e.Name)
if err != nil {
continue
}
path := normalize(e.Name, stat.IsDir())
if e.Op&chmodMask == 0 {
continue
}
names <- path
if e.Op&fsnotify.Create > 0 && stat.IsDir() {
if err := filepath.Walk(path, walker(watcher, reflexes)); err != nil {
infoPrintf(-1, "Error while walking path %s: %s", path, err)
}
}
// TODO: Cannot currently remove fsnotify watches
// recursively, or for deleted files. See:
// https://github.com/cespare/reflex/issues/13
// https://github.com/go-fsnotify/fsnotify/issues/40
// https://github.com/go-fsnotify/fsnotify/issues/41
case err := <-watcher.Errors:
done <- err
return
}
}
} | go | func watch(root string, watcher *fsnotify.Watcher, names chan<- string, done chan<- error, reflexes []*Reflex) {
if err := filepath.Walk(root, walker(watcher, reflexes)); err != nil {
infoPrintf(-1, "Error while walking path %s: %s", root, err)
}
for {
select {
case e := <-watcher.Events:
if verbose {
infoPrintln(-1, "fsnotify event:", e)
}
stat, err := os.Stat(e.Name)
if err != nil {
continue
}
path := normalize(e.Name, stat.IsDir())
if e.Op&chmodMask == 0 {
continue
}
names <- path
if e.Op&fsnotify.Create > 0 && stat.IsDir() {
if err := filepath.Walk(path, walker(watcher, reflexes)); err != nil {
infoPrintf(-1, "Error while walking path %s: %s", path, err)
}
}
// TODO: Cannot currently remove fsnotify watches
// recursively, or for deleted files. See:
// https://github.com/cespare/reflex/issues/13
// https://github.com/go-fsnotify/fsnotify/issues/40
// https://github.com/go-fsnotify/fsnotify/issues/41
case err := <-watcher.Errors:
done <- err
return
}
}
} | [
"func",
"watch",
"(",
"root",
"string",
",",
"watcher",
"*",
"fsnotify",
".",
"Watcher",
",",
"names",
"chan",
"<-",
"string",
",",
"done",
"chan",
"<-",
"error",
",",
"reflexes",
"[",
"]",
"*",
"Reflex",
")",
"{",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"root",
",",
"walker",
"(",
"watcher",
",",
"reflexes",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"infoPrintf",
"(",
"-",
"1",
",",
"\"",
"\"",
",",
"root",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"e",
":=",
"<-",
"watcher",
".",
"Events",
":",
"if",
"verbose",
"{",
"infoPrintln",
"(",
"-",
"1",
",",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"stat",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"e",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"path",
":=",
"normalize",
"(",
"e",
".",
"Name",
",",
"stat",
".",
"IsDir",
"(",
")",
")",
"\n",
"if",
"e",
".",
"Op",
"&",
"chmodMask",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"names",
"<-",
"path",
"\n",
"if",
"e",
".",
"Op",
"&",
"fsnotify",
".",
"Create",
">",
"0",
"&&",
"stat",
".",
"IsDir",
"(",
")",
"{",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"path",
",",
"walker",
"(",
"watcher",
",",
"reflexes",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"infoPrintf",
"(",
"-",
"1",
",",
"\"",
"\"",
",",
"path",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// TODO: Cannot currently remove fsnotify watches",
"// recursively, or for deleted files. See:",
"// https://github.com/cespare/reflex/issues/13",
"// https://github.com/go-fsnotify/fsnotify/issues/40",
"// https://github.com/go-fsnotify/fsnotify/issues/41",
"case",
"err",
":=",
"<-",
"watcher",
".",
"Errors",
":",
"done",
"<-",
"err",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // watch recursively watches changes in root and reports the filenames to names.
// It sends an error on the done chan.
// As an optimization, any dirs we encounter that meet the ExcludePrefix
// criteria of all reflexes can be ignored. | [
"watch",
"recursively",
"watches",
"changes",
"in",
"root",
"and",
"reports",
"the",
"filenames",
"to",
"names",
".",
"It",
"sends",
"an",
"error",
"on",
"the",
"done",
"chan",
".",
"As",
"an",
"optimization",
"any",
"dirs",
"we",
"encounter",
"that",
"meet",
"the",
"ExcludePrefix",
"criteria",
"of",
"all",
"reflexes",
"can",
"be",
"ignored",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/watch.go#L17-L52 | train |
cespare/reflex | reflex.go | NewReflex | func NewReflex(c *Config) (*Reflex, error) {
matcher, err := ParseMatchers(c.regexes, c.inverseRegexes, c.globs, c.inverseGlobs)
if err != nil {
return nil, fmt.Errorf("error parsing glob/regex: %s", err)
}
if !c.allFiles {
matcher = multiMatcher{defaultExcludeMatcher, matcher}
}
if len(c.command) == 0 {
return nil, errors.New("must give command to execute")
}
if c.subSymbol == "" {
return nil, errors.New("substitution symbol must be non-empty")
}
substitution := false
for _, part := range c.command {
if strings.Contains(part, c.subSymbol) {
substitution = true
break
}
}
var backlog Backlog
if substitution {
if c.startService {
return nil, errors.New("using --start-service does not work with a command that has a substitution symbol")
}
backlog = NewUniqueFilesBacklog()
} else {
backlog = NewUnifiedBacklog()
}
if c.onlyFiles && c.onlyDirs {
return nil, errors.New("cannot specify both --only-files and --only-dirs")
}
if c.shutdownTimeout <= 0 {
return nil, errors.New("shutdown timeout cannot be <= 0")
}
reflex := &Reflex{
id: reflexID,
source: c.source,
startService: c.startService,
backlog: backlog,
matcher: matcher,
onlyFiles: c.onlyFiles,
onlyDirs: c.onlyDirs,
command: c.command,
subSymbol: c.subSymbol,
done: make(chan struct{}),
timeout: c.shutdownTimeout,
mu: &sync.Mutex{},
}
reflexID++
return reflex, nil
} | go | func NewReflex(c *Config) (*Reflex, error) {
matcher, err := ParseMatchers(c.regexes, c.inverseRegexes, c.globs, c.inverseGlobs)
if err != nil {
return nil, fmt.Errorf("error parsing glob/regex: %s", err)
}
if !c.allFiles {
matcher = multiMatcher{defaultExcludeMatcher, matcher}
}
if len(c.command) == 0 {
return nil, errors.New("must give command to execute")
}
if c.subSymbol == "" {
return nil, errors.New("substitution symbol must be non-empty")
}
substitution := false
for _, part := range c.command {
if strings.Contains(part, c.subSymbol) {
substitution = true
break
}
}
var backlog Backlog
if substitution {
if c.startService {
return nil, errors.New("using --start-service does not work with a command that has a substitution symbol")
}
backlog = NewUniqueFilesBacklog()
} else {
backlog = NewUnifiedBacklog()
}
if c.onlyFiles && c.onlyDirs {
return nil, errors.New("cannot specify both --only-files and --only-dirs")
}
if c.shutdownTimeout <= 0 {
return nil, errors.New("shutdown timeout cannot be <= 0")
}
reflex := &Reflex{
id: reflexID,
source: c.source,
startService: c.startService,
backlog: backlog,
matcher: matcher,
onlyFiles: c.onlyFiles,
onlyDirs: c.onlyDirs,
command: c.command,
subSymbol: c.subSymbol,
done: make(chan struct{}),
timeout: c.shutdownTimeout,
mu: &sync.Mutex{},
}
reflexID++
return reflex, nil
} | [
"func",
"NewReflex",
"(",
"c",
"*",
"Config",
")",
"(",
"*",
"Reflex",
",",
"error",
")",
"{",
"matcher",
",",
"err",
":=",
"ParseMatchers",
"(",
"c",
".",
"regexes",
",",
"c",
".",
"inverseRegexes",
",",
"c",
".",
"globs",
",",
"c",
".",
"inverseGlobs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"c",
".",
"allFiles",
"{",
"matcher",
"=",
"multiMatcher",
"{",
"defaultExcludeMatcher",
",",
"matcher",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"command",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"subSymbol",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"substitution",
":=",
"false",
"\n",
"for",
"_",
",",
"part",
":=",
"range",
"c",
".",
"command",
"{",
"if",
"strings",
".",
"Contains",
"(",
"part",
",",
"c",
".",
"subSymbol",
")",
"{",
"substitution",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"backlog",
"Backlog",
"\n",
"if",
"substitution",
"{",
"if",
"c",
".",
"startService",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"backlog",
"=",
"NewUniqueFilesBacklog",
"(",
")",
"\n",
"}",
"else",
"{",
"backlog",
"=",
"NewUnifiedBacklog",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"onlyFiles",
"&&",
"c",
".",
"onlyDirs",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"shutdownTimeout",
"<=",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"reflex",
":=",
"&",
"Reflex",
"{",
"id",
":",
"reflexID",
",",
"source",
":",
"c",
".",
"source",
",",
"startService",
":",
"c",
".",
"startService",
",",
"backlog",
":",
"backlog",
",",
"matcher",
":",
"matcher",
",",
"onlyFiles",
":",
"c",
".",
"onlyFiles",
",",
"onlyDirs",
":",
"c",
".",
"onlyDirs",
",",
"command",
":",
"c",
".",
"command",
",",
"subSymbol",
":",
"c",
".",
"subSymbol",
",",
"done",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"timeout",
":",
"c",
".",
"shutdownTimeout",
",",
"mu",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n",
"reflexID",
"++",
"\n\n",
"return",
"reflex",
",",
"nil",
"\n",
"}"
] | // NewReflex prepares a Reflex from a Config, with sanity checking. | [
"NewReflex",
"prepares",
"a",
"Reflex",
"from",
"a",
"Config",
"with",
"sanity",
"checking",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/reflex.go#L43-L102 | train |
cespare/reflex | reflex.go | runCommand | func (r *Reflex) runCommand(name string, stdout chan<- OutMsg) {
command := replaceSubSymbol(r.command, r.subSymbol, name)
cmd := exec.Command(command[0], command[1:]...)
r.cmd = cmd
if flagSequential {
seqCommands.Lock()
}
tty, err := pty.Start(cmd)
if err != nil {
infoPrintln(r.id, err)
return
}
r.tty = tty
// Handle pty size.
chResize := make(chan os.Signal, 1)
signal.Notify(chResize, syscall.SIGWINCH)
go func() {
for range chResize {
// Intentionally ignore errors in case stdout is not a tty
pty.InheritSize(os.Stdout, tty)
}
}()
chResize <- syscall.SIGWINCH // Initial resize.
go func() {
scanner := bufio.NewScanner(tty)
for scanner.Scan() {
stdout <- OutMsg{r.id, scanner.Text()}
}
// Intentionally ignoring scanner.Err() for now. Unfortunately,
// the pty returns a read error when the child dies naturally,
// so I'm just going to ignore errors here unless I can find a
// better way to handle it.
}()
r.mu.Lock()
r.running = true
r.mu.Unlock()
go func() {
err := cmd.Wait()
if !r.Killed() && err != nil {
stdout <- OutMsg{r.id, fmt.Sprintf("(error exit: %s)", err)}
}
r.done <- struct{}{}
signal.Stop(chResize)
close(chResize)
if flagSequential {
seqCommands.Unlock()
}
}()
} | go | func (r *Reflex) runCommand(name string, stdout chan<- OutMsg) {
command := replaceSubSymbol(r.command, r.subSymbol, name)
cmd := exec.Command(command[0], command[1:]...)
r.cmd = cmd
if flagSequential {
seqCommands.Lock()
}
tty, err := pty.Start(cmd)
if err != nil {
infoPrintln(r.id, err)
return
}
r.tty = tty
// Handle pty size.
chResize := make(chan os.Signal, 1)
signal.Notify(chResize, syscall.SIGWINCH)
go func() {
for range chResize {
// Intentionally ignore errors in case stdout is not a tty
pty.InheritSize(os.Stdout, tty)
}
}()
chResize <- syscall.SIGWINCH // Initial resize.
go func() {
scanner := bufio.NewScanner(tty)
for scanner.Scan() {
stdout <- OutMsg{r.id, scanner.Text()}
}
// Intentionally ignoring scanner.Err() for now. Unfortunately,
// the pty returns a read error when the child dies naturally,
// so I'm just going to ignore errors here unless I can find a
// better way to handle it.
}()
r.mu.Lock()
r.running = true
r.mu.Unlock()
go func() {
err := cmd.Wait()
if !r.Killed() && err != nil {
stdout <- OutMsg{r.id, fmt.Sprintf("(error exit: %s)", err)}
}
r.done <- struct{}{}
signal.Stop(chResize)
close(chResize)
if flagSequential {
seqCommands.Unlock()
}
}()
} | [
"func",
"(",
"r",
"*",
"Reflex",
")",
"runCommand",
"(",
"name",
"string",
",",
"stdout",
"chan",
"<-",
"OutMsg",
")",
"{",
"command",
":=",
"replaceSubSymbol",
"(",
"r",
".",
"command",
",",
"r",
".",
"subSymbol",
",",
"name",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
"[",
"0",
"]",
",",
"command",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"r",
".",
"cmd",
"=",
"cmd",
"\n\n",
"if",
"flagSequential",
"{",
"seqCommands",
".",
"Lock",
"(",
")",
"\n",
"}",
"\n\n",
"tty",
",",
"err",
":=",
"pty",
".",
"Start",
"(",
"cmd",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"infoPrintln",
"(",
"r",
".",
"id",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"r",
".",
"tty",
"=",
"tty",
"\n\n",
"// Handle pty size.",
"chResize",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"signal",
".",
"Notify",
"(",
"chResize",
",",
"syscall",
".",
"SIGWINCH",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"range",
"chResize",
"{",
"// Intentionally ignore errors in case stdout is not a tty",
"pty",
".",
"InheritSize",
"(",
"os",
".",
"Stdout",
",",
"tty",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"chResize",
"<-",
"syscall",
".",
"SIGWINCH",
"// Initial resize.",
"\n\n",
"go",
"func",
"(",
")",
"{",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"tty",
")",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"stdout",
"<-",
"OutMsg",
"{",
"r",
".",
"id",
",",
"scanner",
".",
"Text",
"(",
")",
"}",
"\n",
"}",
"\n",
"// Intentionally ignoring scanner.Err() for now. Unfortunately,",
"// the pty returns a read error when the child dies naturally,",
"// so I'm just going to ignore errors here unless I can find a",
"// better way to handle it.",
"}",
"(",
")",
"\n\n",
"r",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"running",
"=",
"true",
"\n",
"r",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"err",
":=",
"cmd",
".",
"Wait",
"(",
")",
"\n",
"if",
"!",
"r",
".",
"Killed",
"(",
")",
"&&",
"err",
"!=",
"nil",
"{",
"stdout",
"<-",
"OutMsg",
"{",
"r",
".",
"id",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"}",
"\n",
"}",
"\n",
"r",
".",
"done",
"<-",
"struct",
"{",
"}",
"{",
"}",
"\n\n",
"signal",
".",
"Stop",
"(",
"chResize",
")",
"\n",
"close",
"(",
"chResize",
")",
"\n\n",
"if",
"flagSequential",
"{",
"seqCommands",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // runCommand runs the given Command. All output is passed line-by-line to the
// stdout channel. | [
"runCommand",
"runs",
"the",
"given",
"Command",
".",
"All",
"output",
"is",
"passed",
"line",
"-",
"by",
"-",
"line",
"to",
"the",
"stdout",
"channel",
"."
] | e1e64e8a6dd7552a6e8f616474c91d4d089eada6 | https://github.com/cespare/reflex/blob/e1e64e8a6dd7552a6e8f616474c91d4d089eada6/reflex.go#L261-L316 | train |
bxcodec/faker | support/slice/helpers.go | Contains | func Contains(slice []string, item string) bool {
set := make(map[string]struct{}, len(slice))
for _, s := range slice {
set[s] = struct{}{}
}
_, ok := set[item]
return ok
} | go | func Contains(slice []string, item string) bool {
set := make(map[string]struct{}, len(slice))
for _, s := range slice {
set[s] = struct{}{}
}
_, ok := set[item]
return ok
} | [
"func",
"Contains",
"(",
"slice",
"[",
"]",
"string",
",",
"item",
"string",
")",
"bool",
"{",
"set",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"slice",
")",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"slice",
"{",
"set",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
":=",
"set",
"[",
"item",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] | // Contains Check item in slice string type | [
"Contains",
"Check",
"item",
"in",
"slice",
"string",
"type"
] | 342a24f52a104690266c76399570254ec476d42c | https://github.com/bxcodec/faker/blob/342a24f52a104690266c76399570254ec476d42c/support/slice/helpers.go#L8-L16 | train |
bxcodec/faker | support/slice/helpers.go | IntToString | func IntToString(intSl []int) (str []string) {
for i := range intSl {
number := intSl[i]
text := strconv.Itoa(number)
str = append(str, text)
}
return str
} | go | func IntToString(intSl []int) (str []string) {
for i := range intSl {
number := intSl[i]
text := strconv.Itoa(number)
str = append(str, text)
}
return str
} | [
"func",
"IntToString",
"(",
"intSl",
"[",
"]",
"int",
")",
"(",
"str",
"[",
"]",
"string",
")",
"{",
"for",
"i",
":=",
"range",
"intSl",
"{",
"number",
":=",
"intSl",
"[",
"i",
"]",
"\n",
"text",
":=",
"strconv",
".",
"Itoa",
"(",
"number",
")",
"\n",
"str",
"=",
"append",
"(",
"str",
",",
"text",
")",
"\n",
"}",
"\n",
"return",
"str",
"\n",
"}"
] | // IntToString Convert slice int to slice string | [
"IntToString",
"Convert",
"slice",
"int",
"to",
"slice",
"string"
] | 342a24f52a104690266c76399570254ec476d42c | https://github.com/bxcodec/faker/blob/342a24f52a104690266c76399570254ec476d42c/support/slice/helpers.go#L19-L26 | train |
bxcodec/faker | price.go | GetPrice | func GetPrice() Money {
mu.Lock()
defer mu.Unlock()
if pri == nil {
pri = &Price{}
}
return pri
} | go | func GetPrice() Money {
mu.Lock()
defer mu.Unlock()
if pri == nil {
pri = &Price{}
}
return pri
} | [
"func",
"GetPrice",
"(",
")",
"Money",
"{",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"pri",
"==",
"nil",
"{",
"pri",
"=",
"&",
"Price",
"{",
"}",
"\n",
"}",
"\n",
"return",
"pri",
"\n",
"}"
] | // GetPrice returns a new Money interface of Price struct | [
"GetPrice",
"returns",
"a",
"new",
"Money",
"interface",
"of",
"Price",
"struct"
] | 342a24f52a104690266c76399570254ec476d42c | https://github.com/bxcodec/faker/blob/342a24f52a104690266c76399570254ec476d42c/price.go#L48-L56 | train |
bxcodec/faker | price.go | Currency | func (p Price) Currency(v reflect.Value) (interface{}, error) {
return p.currency(), nil
} | go | func (p Price) Currency(v reflect.Value) (interface{}, error) {
return p.currency(), nil
} | [
"func",
"(",
"p",
"Price",
")",
"Currency",
"(",
"v",
"reflect",
".",
"Value",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"p",
".",
"currency",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Currency returns a random currency from currencies | [
"Currency",
"returns",
"a",
"random",
"currency",
"from",
"currencies"
] | 342a24f52a104690266c76399570254ec476d42c | https://github.com/bxcodec/faker/blob/342a24f52a104690266c76399570254ec476d42c/price.go#L68-L70 | train |
bxcodec/faker | price.go | AmountWithCurrency | func (p Price) AmountWithCurrency(v reflect.Value) (interface{}, error) {
return p.amountwithcurrency(), nil
} | go | func (p Price) AmountWithCurrency(v reflect.Value) (interface{}, error) {
return p.amountwithcurrency(), nil
} | [
"func",
"(",
"p",
"Price",
")",
"AmountWithCurrency",
"(",
"v",
"reflect",
".",
"Value",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"p",
".",
"amountwithcurrency",
"(",
")",
",",
"nil",
"\n",
"}"
] | // AmountWithCurrency combines both price and currency together | [
"AmountWithCurrency",
"combines",
"both",
"price",
"and",
"currency",
"together"
] | 342a24f52a104690266c76399570254ec476d42c | https://github.com/bxcodec/faker/blob/342a24f52a104690266c76399570254ec476d42c/price.go#L101-L103 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.