_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q34300 | WithWriteTimeoutUDS | train | func WithWriteTimeoutUDS(writeTimeoutUDS time.Duration) Option {
return func(o *Options) error {
o.WriteTimeoutUDS = writeTimeoutUDS
return nil
}
} | go | {
"resource": ""
} |
q34301 | MakeVM | train | func MakeVM() *VM {
return &VM{
MaxStack: 500,
ext: make(vmExtMap),
tla: make(vmExtMap),
nativeFuncs: make(map[string]*NativeFunction),
ErrorFormatter: &termErrorFormatter{pretty: false, maxStackTraceSize: 20},
importer: &FileImporter{},
}
} | go | {
"resource": ""
} |
q34302 | ExtVar | train | func (vm *VM) ExtVar(key string, val string) {
vm.ext[key] = vmExt{value: val, isCode: false}
} | go | {
"resource": ""
} |
q34303 | ExtCode | train | func (vm *VM) ExtCode(key string, val string) {
vm.ext[key] = vmExt{value: val, isCode: true}
} | go | {
"resource": ""
} |
q34304 | TLAVar | train | func (vm *VM) TLAVar(key string, val string) {
vm.tla[key] = vmExt{value: val, isCode: false}
} | go | {
"resource": ""
} |
q34305 | TLACode | train | func (vm *VM) TLACode(key string, val string) {
vm.tla[key] = vmExt{value: val, isCode: true}
} | go | {
"resource": ""
} |
q34306 | NativeFunction | train | func (vm *VM) NativeFunction(f *NativeFunction) {
vm.nativeFuncs[f.Name] = f
} | go | {
"resource": ""
} |
q34307 | EvaluateSnippet | train | func (vm *VM) EvaluateSnippet(filename string, snippet string) (json string, formattedErr error) {
output, err := vm.evaluateSnippet(filename, snippet, evalKindRegular)
if err != nil {
return "", errors.New(vm.ErrorFormatter.Format(err))
}
json = output.(string)
return
} | go | {
"resource": ""
} |
q34308 | EvaluateSnippetStream | train | func (vm *VM) EvaluateSnippetStream(filename string, snippet string) (docs []string, formattedErr error) {
output, err := vm.evaluateSnippet(filename, snippet, evalKindStream)
if err != nil {
return nil, errors.New(vm.ErrorFormatter.Format(err))
}
docs = output.([]string)
return
} | go | {
"resource": ""
} |
q34309 | EvaluateSnippetMulti | train | func (vm *VM) EvaluateSnippetMulti(filename string, snippet string) (files map[string]string, formattedErr error) {
output, err := vm.evaluateSnippet(filename, snippet, evalKindMulti)
if err != nil {
return nil, errors.New(vm.ErrorFormatter.Format(err))
}
files = output.(map[string]string)
return
} | go | {
"resource": ""
} |
q34310 | SnippetToAST | train | func SnippetToAST(filename string, snippet string) (ast.Node, error) {
return snippetToAST(filename, snippet)
} | go | {
"resource": ""
} |
q34311 | findField | train | func findField(curr value, minSuperDepth int, f string) (bool, simpleObjectField, bindingFrame, int) {
switch curr := curr.(type) {
case *valueExtendedObject:
if curr.right.inheritanceSize() > minSuperDepth {
found, field, frame, counter := findField(curr.right, minSuperDepth, f)
if found {
return true, f... | go | {
"resource": ""
} |
q34312 | deInterface | train | func deInterface(v reflect.Value) reflect.Value {
if v.Kind() == reflect.Interface && !v.IsNil() {
v = v.Elem()
}
return v
} | go | {
"resource": ""
} |
q34313 | MakeStaticError | train | func MakeStaticError(msg string, lr ast.LocationRange) StaticError {
return StaticError{Msg: msg, Loc: lr}
} | go | {
"resource": ""
} |
q34314 | Error | train | func (err StaticError) Error() string {
loc := ""
if err.Loc.IsSet() {
loc = err.Loc.String()
}
return fmt.Sprintf("%v %v", loc, err.Msg)
} | go | {
"resource": ""
} |
q34315 | Lint | train | func Lint(node ast.Node, e *ErrorWriter) {
lintingInfo := LintingInfo{
variables: nil,
}
std := variable{
name: "std",
declNode: nil,
uses: nil,
param: false,
}
findVariables(node, &lintingInfo, vScope{"std": &std})
for _, v := range lintingInfo.variables {
if len(v.uses) == 0 && !v.param {... | go | {
"resource": ""
} |
q34316 | MakeImportCache | train | func MakeImportCache(importer Importer) *ImportCache {
return &ImportCache{
importer: importer,
foundAtVerification: make(map[string]Contents),
codeCache: make(map[string]potentialValue),
}
} | go | {
"resource": ""
} |
q34317 | ImportString | train | func (cache *ImportCache) ImportString(importedFrom, importedPath string, i *interpreter, trace TraceElement) (*valueString, error) {
data, _, err := cache.importData(importedFrom, importedPath)
if err != nil {
return nil, i.Error(err.Error(), trace)
}
return makeValueString(data.String()), nil
} | go | {
"resource": ""
} |
q34318 | ImportCode | train | func (cache *ImportCache) ImportCode(importedFrom, importedPath string, i *interpreter, trace TraceElement) (value, error) {
contents, foundAt, err := cache.importData(importedFrom, importedPath)
if err != nil {
return nil, i.Error(err.Error(), trace)
}
var pv potentialValue
if cachedPV, isCached := cache.codeCa... | go | {
"resource": ""
} |
q34319 | Import | train | func (importer *FileImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) {
dir, _ := path.Split(importedFrom)
found, content, foundHere, err := importer.tryPath(dir, importedPath)
if err != nil {
return Contents{}, "", err
}
for i := len(importer.JPaths) - 1; !found... | go | {
"resource": ""
} |
q34320 | Import | train | func (importer *MemoryImporter) Import(importedFrom, importedPath string) (contents Contents, foundAt string, err error) {
if content, ok := importer.Data[importedPath]; ok {
return content, importedPath, nil
}
return Contents{}, "", fmt.Errorf("import not available %v", importedPath)
} | go | {
"resource": ""
} |
q34321 | writeOutputStream | train | func writeOutputStream(output []string, outputFile string) error {
var f *os.File
if outputFile == "" {
f = os.Stdout
} else {
var err error
f, err = os.Create(outputFile)
if err != nil {
return err
}
defer f.Close()
}
for _, doc := range output {
_, err := f.WriteString("---\n")
if err != nil... | go | {
"resource": ""
} |
q34322 | checkWhitespace | train | func checkWhitespace(a, b string) int {
i := 0
for ; i < len(a); i++ {
if a[i] != ' ' && a[i] != '\t' {
// a has run out of whitespace and b matched up to this point. Return
// result.
return i
}
if i >= len(b) {
// We ran off the edge of b while a still has whitespace. Return 0 as
// failure.
... | go | {
"resource": ""
} |
q34323 | backup | train | func (l *lexer) backup() {
if l.prev.byteNo == lexEOF {
panic("backup called with no valid previous rune")
}
l.pos = l.prev
l.prev = position{byteNo: lexEOF}
} | go | {
"resource": ""
} |
q34324 | resetTokenStart | train | func (l *lexer) resetTokenStart() {
l.tokenStart = l.pos.byteNo
l.tokenStartLoc = l.location()
} | go | {
"resource": ""
} |
q34325 | lexWhitespace | train | func (l *lexer) lexWhitespace() (int, int) {
r := l.next()
indent := 0
newLines := 0
for ; isWhitespace(r); r = l.next() {
switch r {
case '\r':
// Ignore.
break
case '\n':
indent = 0
newLines++
break
case ' ':
indent++
break
// This only works for \t at the beginning of lines, but... | go | {
"resource": ""
} |
q34326 | lexUntilNewline | train | func (l *lexer) lexUntilNewline() (string, int, int) {
// Compute 'text'.
var buf bytes.Buffer
lastNonSpace := 0
for r := l.next(); r != lexEOF && r != '\n'; r = l.next() {
buf.WriteRune(r)
if !isHorizontalWhitespace(r) {
lastNonSpace = buf.Len()
}
}
l.backup()
// Trim whitespace off the end.
buf.Trunc... | go | {
"resource": ""
} |
q34327 | lexNumber | train | func (l *lexer) lexNumber() error {
// This function should be understood with reference to the linked image:
// http://www.json.org/number.gif
// Note, we deviate from the json.org documentation as follows:
// There is no reason to lex negative numbers as atomic tokens, it is better to parse them
// as a unary o... | go | {
"resource": ""
} |
q34328 | lexIdentifier | train | func (l *lexer) lexIdentifier() {
r := l.next()
if !isIdentifierFirst(r) {
panic("Unexpected character in lexIdentifier")
}
for ; r != lexEOF; r = l.next() {
if !isIdentifier(r) {
break
}
}
l.backup()
switch l.input[l.tokenStart:l.pos.byteNo] {
case "assert":
l.emitToken(tokenAssert)
case "else":
... | go | {
"resource": ""
} |
q34329 | EvalCall | train | func (native *NativeFunction) EvalCall(arguments callArguments, i *interpreter, trace TraceElement) (value, error) {
flatArgs := flattenArgs(arguments, native.Parameters())
nativeArgs := make([]interface{}, 0, len(flatArgs))
for _, arg := range flatArgs {
v, err := i.evaluatePV(arg, trace)
if err != nil {
ret... | go | {
"resource": ""
} |
q34330 | AddIdentifiers | train | func (i IdentifierSet) AddIdentifiers(idents Identifiers) {
for _, ident := range idents {
i.Add(ident)
}
} | go | {
"resource": ""
} |
q34331 | ToOrderedSlice | train | func (i IdentifierSet) ToOrderedSlice() []Identifier {
var s []Identifier
for v := range i {
s = append(s, v)
}
sort.Sort(identifierSorter(s))
return s
} | go | {
"resource": ""
} |
q34332 | NewIdentifierSet | train | func NewIdentifierSet(a ...Identifier) IdentifierSet {
s := make(IdentifierSet)
for _, i := range a {
s.Add(i)
}
return s
} | go | {
"resource": ""
} |
q34333 | Iter | train | func (set IdentifierSet) Iter() <-chan Identifier {
ch := make(chan Identifier)
go func() {
for elem := range set {
ch <- elem
}
close(ch)
}()
return ch
} | go | {
"resource": ""
} |
q34334 | Children | train | func Children(node ast.Node) []ast.Node {
var result []ast.Node
result = append(result, directChildren(node)...)
result = append(result, thunkChildren(node)...)
result = append(result, specialChildren(node)...)
return result
} | go | {
"resource": ""
} |
q34335 | MakeFodderElement | train | func MakeFodderElement(kind FodderKind, blanks int, indent int, comment []string) FodderElement {
if kind == FodderLineEnd && len(comment) > 1 {
panic(fmt.Sprintf("FodderLineEnd but comment == %v.", comment))
}
if kind == FodderInterstitial && blanks > 0 {
panic(fmt.Sprintf("FodderInterstitial but blanks == %d",... | go | {
"resource": ""
} |
q34336 | FodderHasCleanEndline | train | func FodderHasCleanEndline(fodder Fodder) bool {
return len(fodder) > 0 && fodder[len(fodder)-1].Kind != FodderInterstitial
} | go | {
"resource": ""
} |
q34337 | FodderAppend | train | func FodderAppend(a *Fodder, elem FodderElement) {
if FodderHasCleanEndline(*a) && elem.Kind == FodderLineEnd {
if len(elem.Comment) > 0 {
// The line end had a comment, so create a single line paragraph for it.
*a = append(*a, MakeFodderElement(FodderParagraph, elem.Blanks, elem.Indent, elem.Comment))
} els... | go | {
"resource": ""
} |
q34338 | FodderConcat | train | func FodderConcat(a Fodder, b Fodder) Fodder {
if len(a) == 0 {
return b
}
if len(b) == 0 {
return a
}
r := a
// Carefully add the first element of b.
FodderAppend(&r, b[0])
// Add the rest of b.
for i := 1; i < len(b); i++ {
r = append(r, b[i])
}
return r
} | go | {
"resource": ""
} |
q34339 | FodderMoveFront | train | func FodderMoveFront(a *Fodder, b *Fodder) {
*a = FodderConcat(*b, *a)
*b = Fodder{}
} | go | {
"resource": ""
} |
q34340 | FodderEnsureCleanNewline | train | func FodderEnsureCleanNewline(fodder *Fodder) {
if !FodderHasCleanEndline(*fodder) {
FodderAppend(fodder, MakeFodderElement(FodderLineEnd, 0, 0, []string{}))
}
} | go | {
"resource": ""
} |
q34341 | FodderElementCountNewlines | train | func FodderElementCountNewlines(elem FodderElement) int {
switch elem.Kind {
case FodderInterstitial:
return 0
case FodderLineEnd:
return 1
case FodderParagraph:
return len(elem.Comment) + elem.Blanks
}
panic(fmt.Sprintf("Unknown FodderElement kind %d", elem.Kind))
} | go | {
"resource": ""
} |
q34342 | FodderCountNewlines | train | func FodderCountNewlines(fodder Fodder) int {
sum := 0
for _, elem := range fodder {
sum += FodderElementCountNewlines(elem)
}
return sum
} | go | {
"resource": ""
} |
q34343 | NewLiteralFieldSet | train | func NewLiteralFieldSet(a ...LiteralField) LiteralFieldSet {
s := make(LiteralFieldSet)
for _, i := range a {
s.Add(i)
}
return s
} | go | {
"resource": ""
} |
q34344 | Iter | train | func (set LiteralFieldSet) Iter() <-chan LiteralField {
ch := make(chan LiteralField)
go func() {
for elem := range set {
ch <- elem
}
close(ch)
}()
return ch
} | go | {
"resource": ""
} |
q34345 | astVarToIdentifier | train | func astVarToIdentifier(node ast.Node) (*ast.Identifier, bool) {
v, ok := node.(*ast.Var)
if ok {
return &v.Id, true
}
return nil, false
} | go | {
"resource": ""
} |
q34346 | popIfExists | train | func (s *callStack) popIfExists(whichFrame int) {
if len(s.stack) == whichFrame {
if s.top().isCall {
s.calls--
}
s.stack = s.stack[:len(s.stack)-1]
}
} | go | {
"resource": ""
} |
q34347 | tailCallTrimStack | train | func (s *callStack) tailCallTrimStack() {
for i := len(s.stack) - 1; i >= 0; i-- {
if s.stack[i].isCall {
if !s.stack[i].trimmable {
return
}
// Remove this stack frame and everything above it
s.stack = s.stack[:i]
s.calls--
return
}
}
} | go | {
"resource": ""
} |
q34348 | getSelfBinding | train | func (s *callStack) getSelfBinding() selfBinding {
for i := len(s.stack) - 1; i >= 0; i-- {
if s.stack[i].isCall {
return s.stack[i].env.selfBinding
}
}
panic(fmt.Sprintf("malformed stack %v", dumpCallStack(s)))
} | go | {
"resource": ""
} |
q34349 | lookUpVar | train | func (s *callStack) lookUpVar(id ast.Identifier) *cachedThunk {
for i := len(s.stack) - 1; i >= 0; i-- {
bind, present := s.stack[i].env.upValues[id]
if present {
return bind
}
if s.stack[i].isCall {
// Nothing beyond the captured environment of the thunk / closure.
break
}
}
return nil
} | go | {
"resource": ""
} |
q34350 | capture | train | func (s *callStack) capture(freeVars ast.Identifiers) bindingFrame {
env := make(bindingFrame)
for _, fv := range freeVars {
env[fv] = s.lookUpVarOrPanic(fv)
}
return env
} | go | {
"resource": ""
} |
q34351 | addBindings | train | func addBindings(a, b bindingFrame) bindingFrame {
result := make(bindingFrame)
for k, v := range a {
result[k] = v
}
for k, v := range b {
result[k] = v
}
return result
} | go | {
"resource": ""
} |
q34352 | unparseString | train | func unparseString(v string) string {
var buf bytes.Buffer
buf.WriteString("\"")
for _, c := range v {
switch c {
case '"':
buf.WriteString("\\\"")
case '\\':
buf.WriteString("\\\\")
case '\b':
buf.WriteString("\\b")
case '\f':
buf.WriteString("\\f")
case '\n':
buf.WriteString("\\n")
cas... | go | {
"resource": ""
} |
q34353 | manifestString | train | func (i *interpreter) manifestString(buf *bytes.Buffer, trace TraceElement, v value) error {
switch v := v.(type) {
case *valueString:
buf.WriteString(v.getString())
return nil
default:
return makeRuntimeError(fmt.Sprintf("expected string result, got: %s", v.getType().name), i.getCurrentStackTrace(trace))
}
} | go | {
"resource": ""
} |
q34354 | LocationRangeBetween | train | func LocationRangeBetween(a, b *LocationRange) LocationRange {
if a.file != b.file {
panic("Cannot create a LocationRange between different files")
}
return MakeLocationRange(a.FileName, a.file, a.Begin, b.End)
} | go | {
"resource": ""
} |
q34355 | MakeLocationRange | train | func MakeLocationRange(fn string, fc *Source, begin Location, end Location) LocationRange {
return LocationRange{FileName: fn, file: fc, Begin: begin, End: end}
} | go | {
"resource": ""
} |
q34356 | GetSnippet | train | func (sp *SourceProvider) GetSnippet(loc LocationRange) string {
var result bytes.Buffer
if loc.Begin.Line == 0 {
return ""
}
for i := loc.Begin.Line; i <= loc.End.Line; i++ {
inLineRange := trimToLine(loc, i)
for j := inLineRange.Begin.Column; j < inLineRange.End.Column; j++ {
result.WriteByte(loc.file.li... | go | {
"resource": ""
} |
q34357 | NewNodeBase | train | func NewNodeBase(loc LocationRange, freeVariables Identifiers) NodeBase {
return NodeBase{
loc: loc,
freeVariables: freeVariables,
}
} | go | {
"resource": ""
} |
q34358 | FullyEscaped | train | func (k LiteralStringKind) FullyEscaped() bool {
switch k {
case StringSingle, StringDouble:
return true
case StringBlock, VerbatimStringDouble, VerbatimStringSingle:
return false
}
panic(fmt.Sprintf("Unknown string kind: %v", k))
} | go | {
"resource": ""
} |
q34359 | ObjectFieldLocalNoMethod | train | func ObjectFieldLocalNoMethod(id *Identifier, body Node) ObjectField {
return ObjectField{ObjectLocal, ObjectFieldVisible, false, false, nil, nil, id, nil, false, body, nil}
} | go | {
"resource": ""
} |
q34360 | cloneForSpec | train | func cloneForSpec(specPtr *ForSpec) {
clone(&specPtr.Expr)
oldOuter := specPtr.Outer
if oldOuter != nil {
specPtr.Outer = new(ForSpec)
*specPtr.Outer = *oldOuter
cloneForSpec(specPtr.Outer)
}
for i := range specPtr.Conditions {
clone(&specPtr.Conditions[i].Expr)
}
} | go | {
"resource": ""
} |
q34361 | cloneParameters | train | func cloneParameters(params *Parameters) {
if params == nil {
return
}
params.Optional = append(make([]NamedParameter, 0), params.Optional...)
for i := range params.Optional {
clone(¶ms.Optional[i].DefaultArg)
}
} | go | {
"resource": ""
} |
q34362 | cloneField | train | func cloneField(field *ObjectField) {
if field.Method != nil {
field.Method = Clone(field.Method).(*Function)
}
oldParams := field.Params
if oldParams != nil {
field.Params = new(Parameters)
*field.Params = *oldParams
}
cloneParameters(field.Params)
clone(&field.Expr1)
clone(&field.Expr2)
clone(&field.... | go | {
"resource": ""
} |
q34363 | cloneNodeBase | train | func cloneNodeBase(astPtr Node) {
if astPtr.Context() != nil {
newContext := new(string)
*newContext = *astPtr.Context()
astPtr.SetContext(newContext)
}
astPtr.SetFreeVariables(append(make(Identifiers, 0), astPtr.FreeVariables()...))
} | go | {
"resource": ""
} |
q34364 | getAllAndReusedPointers | train | func (pm *pointerMap) getAllAndReusedPointers(v reflect.Value) {
if v.Kind() == reflect.Invalid {
return
}
if isPointerValue(v) && v.Pointer() != 0 { // pointer is 0 for unexported fields
reused := pm.addPointer(v.Pointer())
if reused {
// No use descending inside this value, since it have been seen before ... | go | {
"resource": ""
} |
q34365 | ForStruct | train | func ForStruct(s interface{}, fields ...string) (Associations, error) {
associations := Associations{}
innerAssociations := InnerAssociations{}
t, v := getModelDefinition(s)
fields = trimFields(fields)
// validate if fields contains a non existing field in struct.
// and vefiry is it has inner associations.
fo... | go | {
"resource": ""
} |
q34366 | Scan | train | func (s *UUID) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
us, err := strSliceToUUIDSlice(strToUUID(string(b)))
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | go | {
"resource": ""
} |
q34367 | Value | train | func (s UUID) Value() (driver.Value, error) {
ss := make([]string, len(s))
for i, u := range s {
ss[i] = u.String()
}
return fmt.Sprintf("{%s}", strings.Join(ss, ",")), nil
} | go | {
"resource": ""
} |
q34368 | UnmarshalJSON | train | func (s *UUID) UnmarshalJSON(data []byte) error {
var ss []string
if err := json.Unmarshal(data, &ss); err != nil {
return err
}
us, err := strSliceToUUIDSlice(ss)
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | go | {
"resource": ""
} |
q34369 | UnmarshalText | train | func (s *UUID) UnmarshalText(text []byte) error {
var ss []string
for _, x := range strings.Split(string(text), ",") {
ss = append(ss, strings.TrimSpace(x))
}
us, err := strSliceToUUIDSlice(ss)
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | go | {
"resource": ""
} |
q34370 | MigrationCreate | train | func MigrationCreate(path, name, ext string, up, down []byte) error {
g := makr.New()
n := time.Now().UTC()
s := n.Format("20060102150405")
upf := filepath.Join(path, fmt.Sprintf("%s_%s.up.%s", s, name, ext))
g.Add(makr.NewFile(upf, string(up)))
downf := filepath.Join(path, fmt.Sprintf("%s_%s.down.%s", s, name,... | go | {
"resource": ""
} |
q34371 | NewMigrator | train | func NewMigrator(c *Connection) Migrator {
return Migrator{
Connection: c,
Migrations: map[string]Migrations{
"up": {},
"down": {},
},
}
} | go | {
"resource": ""
} |
q34372 | UpLogOnly | train | func (m Migrator) UpLogOnly() error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
mfs := m.Migrations["up"]
sort.Sort(mfs)
return c.Transaction(func(tx *Connection) error {
for _, mi := range mfs {
if mi.DBType != "all" && mi.DBType != c.Dialect.Name() {
// Skip mi... | go | {
"resource": ""
} |
q34373 | Up | train | func (m Migrator) Up() error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
mfs := m.Migrations["up"]
sort.Sort(mfs)
applied := 0
for _, mi := range mfs {
if mi.DBType != "all" && mi.DBType != c.Dialect.Name() {
// Skip migration for non-matching dialect
continue
... | go | {
"resource": ""
} |
q34374 | Down | train | func (m Migrator) Down(step int) error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
count, err := c.Count(mtn)
if err != nil {
return errors.Wrap(err, "migration down: unable count existing migration")
}
mfs := m.Migrations["down"]
sort.Sort(sort.Reverse(mfs))
// ski... | go | {
"resource": ""
} |
q34375 | Reset | train | func (m Migrator) Reset() error {
err := m.Down(-1)
if err != nil {
return errors.WithStack(err)
}
return m.Up()
} | go | {
"resource": ""
} |
q34376 | CreateSchemaMigrations | train | func (m Migrator) CreateSchemaMigrations() error {
c := m.Connection
mtn := c.MigrationTableName()
err := c.Open()
if err != nil {
return errors.Wrap(err, "could not open connection")
}
_, err = c.Store.Exec(fmt.Sprintf("select * from %s", mtn))
if err == nil {
return nil
}
return c.Transaction(func(tx *C... | go | {
"resource": ""
} |
q34377 | DumpMigrationSchema | train | func (m Migrator) DumpMigrationSchema() error {
if m.SchemaPath == "" {
return nil
}
c := m.Connection
schema := filepath.Join(m.SchemaPath, "schema.sql")
f, err := os.Create(schema)
if err != nil {
return errors.WithStack(err)
}
err = c.Dialect.DumpSchema(f)
if err != nil {
os.RemoveAll(schema)
return... | go | {
"resource": ""
} |
q34378 | DialectSupported | train | func DialectSupported(d string) bool {
for _, ad := range AvailableDialects {
if ad == d {
return true
}
}
return false
} | go | {
"resource": ""
} |
q34379 | UpdateString | train | func (c Column) UpdateString() string {
return fmt.Sprintf("%s = :%s", c.Name, c.Name)
} | go | {
"resource": ""
} |
q34380 | SetSelectSQL | train | func (c *Column) SetSelectSQL(s string) {
c.SelectSQL = s
c.Writeable = false
c.Readable = true
} | go | {
"resource": ""
} |
q34381 | Join | train | func (q *Query) Join(table string, on string, args ...interface{}) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.joinClauses = append(q.joinClauses, joinClause{"JOIN", table, on, args})
return q
} | go | {
"resource": ""
} |
q34382 | Clone | train | func (q *Query) Clone(targetQ *Query) {
rawSQL := *q.RawSQL
targetQ.RawSQL = &rawSQL
targetQ.limitResults = q.limitResults
targetQ.whereClauses = q.whereClauses
targetQ.orderClauses = q.orderClauses
targetQ.fromClauses = q.fromClauses
targetQ.belongsToThroughClauses = q.belongsToThroughClauses
targetQ.joinClau... | go | {
"resource": ""
} |
q34383 | disableEager | train | func (q *Query) disableEager() {
q.Connection.eager, q.eager = false, false
q.Connection.eagerFields, q.eagerFields = []string{}, []string{}
} | go | {
"resource": ""
} |
q34384 | Q | train | func Q(c *Connection) *Query {
return &Query{
RawSQL: &clause{},
Connection: c,
eager: c.eager,
eagerFields: c.eagerFields,
}
} | go | {
"resource": ""
} |
q34385 | ToSQL | train | func (q Query) ToSQL(model *Model, addColumns ...string) (string, []interface{}) {
sb := q.toSQLBuilder(model, addColumns...)
return sb.String(), sb.Args()
} | go | {
"resource": ""
} |
q34386 | toSQLBuilder | train | func (q Query) toSQLBuilder(model *Model, addColumns ...string) *sqlBuilder {
if len(q.addColumns) != 0 {
addColumns = q.addColumns
}
return newSQLBuilder(q, model, addColumns...)
} | go | {
"resource": ""
} |
q34387 | Having | train | func (q *Query) Having(condition string, args ...interface{}) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.havingClauses = append(q.havingClauses, HavingClause{condition, args})
return q
} | go | {
"resource": ""
} |
q34388 | Scan | train | func (m *Map) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
err := json.Unmarshal(b, m)
if err != nil {
return errors.WithStack(err)
}
return nil
} | go | {
"resource": ""
} |
q34389 | Value | train | func (m Map) Value() (driver.Value, error) {
b, err := json.Marshal(m)
if err != nil {
return nil, errors.WithStack(err)
}
return string(b), nil
} | go | {
"resource": ""
} |
q34390 | UnmarshalJSON | train | func (m Map) UnmarshalJSON(b []byte) error {
var stuff map[string]interface{}
err := json.Unmarshal(b, &stuff)
if err != nil {
return err
}
for key, value := range stuff {
m[key] = value
}
return nil
} | go | {
"resource": ""
} |
q34391 | UnmarshalText | train | func (m Map) UnmarshalText(text []byte) error {
err := json.Unmarshal(text, &m)
if err != nil {
return errors.WithStack(err)
}
return nil
} | go | {
"resource": ""
} |
q34392 | ID | train | func (m *Model) ID() interface{} {
fbn, err := m.fieldByName("ID")
if err != nil {
return 0
}
if m.PrimaryKeyType() == "UUID" {
return fbn.Interface().(uuid.UUID).String()
}
return fbn.Interface()
} | go | {
"resource": ""
} |
q34393 | PrimaryKeyType | train | func (m *Model) PrimaryKeyType() string {
fbn, err := m.fieldByName("ID")
if err != nil {
return "int"
}
return fbn.Type().Name()
} | go | {
"resource": ""
} |
q34394 | TableName | train | func (m *Model) TableName() string {
if s, ok := m.Value.(string); ok {
return s
}
if n, ok := m.Value.(TableNameAble); ok {
return n.TableName()
}
if m.tableName != "" {
return m.tableName
}
t := reflect.TypeOf(m.Value)
name := m.typeName(t)
defer tableMapMu.Unlock()
tableMapMu.Lock()
if tableMap[... | go | {
"resource": ""
} |
q34395 | BelongsTo | train | func (q *Query) BelongsTo(model interface{}) *Query {
m := &Model{Value: model}
q.Where(fmt.Sprintf("%s = ?", m.associationName()), m.ID())
return q
} | go | {
"resource": ""
} |
q34396 | NewMigrationBox | train | func NewMigrationBox(box packd.Walkable, c *Connection) (MigrationBox, error) {
fm := MigrationBox{
Migrator: NewMigrator(c),
Box: box,
}
err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
}
return fm, nil
} | go | {
"resource": ""
} |
q34397 | Fizz | train | func (m model) Fizz() string {
s := []string{fmt.Sprintf("create_table(\"%s\") {", m.Name.Tableize())}
for _, a := range m.Attributes {
switch a.Name.String() {
case "created_at", "updated_at":
default:
col := fizz.Column{
Name: a.Name.Underscore().String(),
ColType: fizzColType(a.OriginalType),
... | go | {
"resource": ""
} |
q34398 | GenerateSQLFromFizz | train | func (m model) GenerateSQLFromFizz(content string, f fizz.Translator) string {
content, err := fizz.AString(content, f)
if err != nil {
return ""
}
return content
} | go | {
"resource": ""
} |
q34399 | Parse | train | func (nulls *Nulls) Parse(value interface{}) interface{} {
switch nulls.Value.(type) {
case Int:
return NewInt(value.(int))
case Int64:
return NewInt64(value.(int64))
case UUID:
return NewUUID(value.(uuid.UUID))
default:
return value
}
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.