id int32 0 167k | 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 listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
13,900 | mikespook/gearman-go | worker/worker.go | Reset | func (worker *Worker) Reset() {
outpack := getOutPack()
outpack.dataType = dtResetAbilities
worker.broadcast(outpack)
worker.funcs = make(jobFuncs)
} | go | func (worker *Worker) Reset() {
outpack := getOutPack()
outpack.dataType = dtResetAbilities
worker.broadcast(outpack)
worker.funcs = make(jobFuncs)
} | [
"func",
"(",
"worker",
"*",
"Worker",
")",
"Reset",
"(",
")",
"{",
"outpack",
":=",
"getOutPack",
"(",
")",
"\n",
"outpack",
".",
"dataType",
"=",
"dtResetAbilities",
"\n",
"worker",
".",
"broadcast",
"(",
"outpack",
")",
"\n",
"worker",
".",
"funcs",
... | // Reset removes all of functions.
// Both from the worker and job servers. | [
"Reset",
"removes",
"all",
"of",
"functions",
".",
"Both",
"from",
"the",
"worker",
"and",
"job",
"servers",
"."
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L242-L247 |
13,901 | mikespook/gearman-go | worker/worker.go | SetId | func (worker *Worker) SetId(id string) {
worker.Id = id
outpack := getOutPack()
outpack.dataType = dtSetClientId
outpack.data = []byte(id)
worker.broadcast(outpack)
} | go | func (worker *Worker) SetId(id string) {
worker.Id = id
outpack := getOutPack()
outpack.dataType = dtSetClientId
outpack.data = []byte(id)
worker.broadcast(outpack)
} | [
"func",
"(",
"worker",
"*",
"Worker",
")",
"SetId",
"(",
"id",
"string",
")",
"{",
"worker",
".",
"Id",
"=",
"id",
"\n",
"outpack",
":=",
"getOutPack",
"(",
")",
"\n",
"outpack",
".",
"dataType",
"=",
"dtSetClientId",
"\n",
"outpack",
".",
"data",
"=... | // Set the worker's unique id. | [
"Set",
"the",
"worker",
"s",
"unique",
"id",
"."
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L250-L256 |
13,902 | mikespook/gearman-go | worker/worker.go | exec | func (worker *Worker) exec(inpack *inPack) (err error) {
defer func() {
if worker.limit != nil {
<-worker.limit
}
if r := recover(); r != nil {
if e, ok := r.(error); ok {
err = e
} else {
err = ErrUnknown
}
}
}()
f, ok := worker.funcs[inpack.fn]
if !ok {
return fmt.Errorf("The function does not exist: %s", inpack.fn)
}
var r *result
if f.timeout == 0 {
d, e := f.f(inpack)
r = &result{data: d, err: e}
} else {
r = execTimeout(f.f, inpack, time.Duration(f.timeout)*time.Second)
}
if worker.running {
outpack := getOutPack()
if r.err == nil {
outpack.dataType = dtWorkComplete
} else {
if len(r.data) == 0 {
outpack.dataType = dtWorkFail
} else {
outpack.dataType = dtWorkException
}
err = r.err
}
outpack.handle = inpack.handle
outpack.data = r.data
inpack.a.Write(outpack)
}
return
} | go | func (worker *Worker) exec(inpack *inPack) (err error) {
defer func() {
if worker.limit != nil {
<-worker.limit
}
if r := recover(); r != nil {
if e, ok := r.(error); ok {
err = e
} else {
err = ErrUnknown
}
}
}()
f, ok := worker.funcs[inpack.fn]
if !ok {
return fmt.Errorf("The function does not exist: %s", inpack.fn)
}
var r *result
if f.timeout == 0 {
d, e := f.f(inpack)
r = &result{data: d, err: e}
} else {
r = execTimeout(f.f, inpack, time.Duration(f.timeout)*time.Second)
}
if worker.running {
outpack := getOutPack()
if r.err == nil {
outpack.dataType = dtWorkComplete
} else {
if len(r.data) == 0 {
outpack.dataType = dtWorkFail
} else {
outpack.dataType = dtWorkException
}
err = r.err
}
outpack.handle = inpack.handle
outpack.data = r.data
inpack.a.Write(outpack)
}
return
} | [
"func",
"(",
"worker",
"*",
"Worker",
")",
"exec",
"(",
"inpack",
"*",
"inPack",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"worker",
".",
"limit",
"!=",
"nil",
"{",
"<-",
"worker",
".",
"limit",
"\n",
"}",
"\n",
... | // inner job executing | [
"inner",
"job",
"executing"
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L259-L300 |
13,903 | mikespook/gearman-go | worker/worker.go | Server | func (e *WorkerDisconnectError) Server() (net string, addr string) {
return e.agent.net, e.agent.addr
} | go | func (e *WorkerDisconnectError) Server() (net string, addr string) {
return e.agent.net, e.agent.addr
} | [
"func",
"(",
"e",
"*",
"WorkerDisconnectError",
")",
"Server",
"(",
")",
"(",
"net",
"string",
",",
"addr",
"string",
")",
"{",
"return",
"e",
".",
"agent",
".",
"net",
",",
"e",
".",
"agent",
".",
"addr",
"\n",
"}"
] | // Which server was this for? | [
"Which",
"server",
"was",
"this",
"for?"
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L350-L352 |
13,904 | mikespook/gearman-go | client/response.go | Result | func (resp *Response) Result() (data []byte, err error) {
switch resp.DataType {
case dtWorkFail:
resp.Handle = string(resp.Data)
err = ErrWorkFail
return
case dtWorkException:
err = ErrWorkException
fallthrough
case dtWorkComplete:
data = resp.Data
default:
err = ErrDataType
}
return
} | go | func (resp *Response) Result() (data []byte, err error) {
switch resp.DataType {
case dtWorkFail:
resp.Handle = string(resp.Data)
err = ErrWorkFail
return
case dtWorkException:
err = ErrWorkException
fallthrough
case dtWorkComplete:
data = resp.Data
default:
err = ErrDataType
}
return
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"Result",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"switch",
"resp",
".",
"DataType",
"{",
"case",
"dtWorkFail",
":",
"resp",
".",
"Handle",
"=",
"string",
"(",
"resp",
".",
... | // Extract the Response's result.
// if data == nil, err != nil, then worker failing to execute job
// if data != nil, err != nil, then worker has a exception
// if data != nil, err == nil, then worker complate job
// after calling this method, the Response.Handle will be filled | [
"Extract",
"the",
"Response",
"s",
"result",
".",
"if",
"data",
"==",
"nil",
"err",
"!",
"=",
"nil",
"then",
"worker",
"failing",
"to",
"execute",
"job",
"if",
"data",
"!",
"=",
"nil",
"err",
"!",
"=",
"nil",
"then",
"worker",
"has",
"a",
"exception"... | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/response.go#L25-L40 |
13,905 | mikespook/gearman-go | client/response.go | Update | func (resp *Response) Update() (data []byte, err error) {
if resp.DataType != dtWorkData &&
resp.DataType != dtWorkWarning {
err = ErrDataType
return
}
data = resp.Data
if resp.DataType == dtWorkWarning {
err = ErrWorkWarning
}
return
} | go | func (resp *Response) Update() (data []byte, err error) {
if resp.DataType != dtWorkData &&
resp.DataType != dtWorkWarning {
err = ErrDataType
return
}
data = resp.Data
if resp.DataType == dtWorkWarning {
err = ErrWorkWarning
}
return
} | [
"func",
"(",
"resp",
"*",
"Response",
")",
"Update",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"resp",
".",
"DataType",
"!=",
"dtWorkData",
"&&",
"resp",
".",
"DataType",
"!=",
"dtWorkWarning",
"{",
"err",
"=",
"... | // Extract the job's update | [
"Extract",
"the",
"job",
"s",
"update"
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/response.go#L43-L54 |
13,906 | mikespook/gearman-go | client/response.go | decodeResponse | func decodeResponse(data []byte) (resp *Response, l int, err error) {
a := len(data)
if a < minPacketLength { // valid package should not less 12 bytes
err = fmt.Errorf("Invalid data: %v", data)
return
}
dl := int(binary.BigEndian.Uint32(data[8:12]))
if a < minPacketLength+dl {
err = fmt.Errorf("Invalid data: %v", data)
return
}
dt := data[minPacketLength : dl+minPacketLength]
if len(dt) != int(dl) { // length not equal
err = fmt.Errorf("Invalid data: %v", data)
return
}
resp = getResponse()
resp.DataType = binary.BigEndian.Uint32(data[4:8])
switch resp.DataType {
case dtJobCreated:
resp.Handle = string(dt)
case dtStatusRes, dtWorkData, dtWorkWarning, dtWorkStatus,
dtWorkComplete, dtWorkException:
s := bytes.SplitN(dt, []byte{'\x00'}, 2)
if len(s) >= 2 {
resp.Handle = string(s[0])
resp.Data = s[1]
} else {
err = fmt.Errorf("Invalid data: %v", data)
return
}
case dtWorkFail:
s := bytes.SplitN(dt, []byte{'\x00'}, 2)
if len(s) >= 1 {
resp.Handle = string(s[0])
} else {
err = fmt.Errorf("Invalid data: %v", data)
return
}
case dtEchoRes:
fallthrough
default:
resp.Data = dt
}
l = dl + minPacketLength
return
} | go | func decodeResponse(data []byte) (resp *Response, l int, err error) {
a := len(data)
if a < minPacketLength { // valid package should not less 12 bytes
err = fmt.Errorf("Invalid data: %v", data)
return
}
dl := int(binary.BigEndian.Uint32(data[8:12]))
if a < minPacketLength+dl {
err = fmt.Errorf("Invalid data: %v", data)
return
}
dt := data[minPacketLength : dl+minPacketLength]
if len(dt) != int(dl) { // length not equal
err = fmt.Errorf("Invalid data: %v", data)
return
}
resp = getResponse()
resp.DataType = binary.BigEndian.Uint32(data[4:8])
switch resp.DataType {
case dtJobCreated:
resp.Handle = string(dt)
case dtStatusRes, dtWorkData, dtWorkWarning, dtWorkStatus,
dtWorkComplete, dtWorkException:
s := bytes.SplitN(dt, []byte{'\x00'}, 2)
if len(s) >= 2 {
resp.Handle = string(s[0])
resp.Data = s[1]
} else {
err = fmt.Errorf("Invalid data: %v", data)
return
}
case dtWorkFail:
s := bytes.SplitN(dt, []byte{'\x00'}, 2)
if len(s) >= 1 {
resp.Handle = string(s[0])
} else {
err = fmt.Errorf("Invalid data: %v", data)
return
}
case dtEchoRes:
fallthrough
default:
resp.Data = dt
}
l = dl + minPacketLength
return
} | [
"func",
"decodeResponse",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"resp",
"*",
"Response",
",",
"l",
"int",
",",
"err",
"error",
")",
"{",
"a",
":=",
"len",
"(",
"data",
")",
"\n",
"if",
"a",
"<",
"minPacketLength",
"{",
"// valid package should not l... | // Decode a job from byte slice | [
"Decode",
"a",
"job",
"from",
"byte",
"slice"
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/response.go#L57-L103 |
13,907 | mikespook/gearman-go | worker/inpack.go | SendData | func (inpack *inPack) SendData(data []byte) {
outpack := getOutPack()
outpack.dataType = dtWorkData
hl := len(inpack.handle)
l := hl + len(data) + 1
outpack.data = getBuffer(l)
copy(outpack.data, []byte(inpack.handle))
copy(outpack.data[hl+1:], data)
inpack.a.write(outpack)
} | go | func (inpack *inPack) SendData(data []byte) {
outpack := getOutPack()
outpack.dataType = dtWorkData
hl := len(inpack.handle)
l := hl + len(data) + 1
outpack.data = getBuffer(l)
copy(outpack.data, []byte(inpack.handle))
copy(outpack.data[hl+1:], data)
inpack.a.write(outpack)
} | [
"func",
"(",
"inpack",
"*",
"inPack",
")",
"SendData",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"outpack",
":=",
"getOutPack",
"(",
")",
"\n",
"outpack",
".",
"dataType",
"=",
"dtWorkData",
"\n",
"hl",
":=",
"len",
"(",
"inpack",
".",
"handle",
")",
... | // Send some datas to client.
// Using this in a job's executing. | [
"Send",
"some",
"datas",
"to",
"client",
".",
"Using",
"this",
"in",
"a",
"job",
"s",
"executing",
"."
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/inpack.go#L48-L57 |
13,908 | mikespook/gearman-go | worker/inpack.go | UpdateStatus | func (inpack *inPack) UpdateStatus(numerator, denominator int) {
n := []byte(strconv.Itoa(numerator))
d := []byte(strconv.Itoa(denominator))
outpack := getOutPack()
outpack.dataType = dtWorkStatus
hl := len(inpack.handle)
nl := len(n)
dl := len(d)
outpack.data = getBuffer(hl + nl + dl + 2)
copy(outpack.data, []byte(inpack.handle))
copy(outpack.data[hl+1:], n)
copy(outpack.data[hl+nl+2:], d)
inpack.a.write(outpack)
} | go | func (inpack *inPack) UpdateStatus(numerator, denominator int) {
n := []byte(strconv.Itoa(numerator))
d := []byte(strconv.Itoa(denominator))
outpack := getOutPack()
outpack.dataType = dtWorkStatus
hl := len(inpack.handle)
nl := len(n)
dl := len(d)
outpack.data = getBuffer(hl + nl + dl + 2)
copy(outpack.data, []byte(inpack.handle))
copy(outpack.data[hl+1:], n)
copy(outpack.data[hl+nl+2:], d)
inpack.a.write(outpack)
} | [
"func",
"(",
"inpack",
"*",
"inPack",
")",
"UpdateStatus",
"(",
"numerator",
",",
"denominator",
"int",
")",
"{",
"n",
":=",
"[",
"]",
"byte",
"(",
"strconv",
".",
"Itoa",
"(",
"numerator",
")",
")",
"\n",
"d",
":=",
"[",
"]",
"byte",
"(",
"strconv... | // Update status.
// Tall client how many percent job has been executed. | [
"Update",
"status",
".",
"Tall",
"client",
"how",
"many",
"percent",
"job",
"has",
"been",
"executed",
"."
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/inpack.go#L72-L85 |
13,909 | mikespook/gearman-go | worker/inpack.go | decodeInPack | func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
if len(data) < minPacketLength { // valid package should not less 12 bytes
err = fmt.Errorf("Invalid data: %v", data)
return
}
dl := int(binary.BigEndian.Uint32(data[8:12]))
if len(data) < (dl + minPacketLength) {
err = fmt.Errorf("Not enough data: %v", data)
return
}
dt := data[minPacketLength : dl+minPacketLength]
if len(dt) != int(dl) { // length not equal
err = fmt.Errorf("Invalid data: %v", data)
return
}
inpack = getInPack()
inpack.dataType = binary.BigEndian.Uint32(data[4:8])
switch inpack.dataType {
case dtJobAssign:
s := bytes.SplitN(dt, []byte{'\x00'}, 3)
if len(s) == 3 {
inpack.handle = string(s[0])
inpack.fn = string(s[1])
inpack.data = s[2]
}
case dtJobAssignUniq:
s := bytes.SplitN(dt, []byte{'\x00'}, 4)
if len(s) == 4 {
inpack.handle = string(s[0])
inpack.fn = string(s[1])
inpack.uniqueId = string(s[2])
inpack.data = s[3]
}
default:
inpack.data = dt
}
l = dl + minPacketLength
return
} | go | func decodeInPack(data []byte) (inpack *inPack, l int, err error) {
if len(data) < minPacketLength { // valid package should not less 12 bytes
err = fmt.Errorf("Invalid data: %v", data)
return
}
dl := int(binary.BigEndian.Uint32(data[8:12]))
if len(data) < (dl + minPacketLength) {
err = fmt.Errorf("Not enough data: %v", data)
return
}
dt := data[minPacketLength : dl+minPacketLength]
if len(dt) != int(dl) { // length not equal
err = fmt.Errorf("Invalid data: %v", data)
return
}
inpack = getInPack()
inpack.dataType = binary.BigEndian.Uint32(data[4:8])
switch inpack.dataType {
case dtJobAssign:
s := bytes.SplitN(dt, []byte{'\x00'}, 3)
if len(s) == 3 {
inpack.handle = string(s[0])
inpack.fn = string(s[1])
inpack.data = s[2]
}
case dtJobAssignUniq:
s := bytes.SplitN(dt, []byte{'\x00'}, 4)
if len(s) == 4 {
inpack.handle = string(s[0])
inpack.fn = string(s[1])
inpack.uniqueId = string(s[2])
inpack.data = s[3]
}
default:
inpack.data = dt
}
l = dl + minPacketLength
return
} | [
"func",
"decodeInPack",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"inpack",
"*",
"inPack",
",",
"l",
"int",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"<",
"minPacketLength",
"{",
"// valid package should not less 12 bytes",
"err",
"=",
... | // Decode job from byte slice | [
"Decode",
"job",
"from",
"byte",
"slice"
] | b902646ce8950409a10952e297dd63b4f459fa13 | https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/inpack.go#L88-L126 |
13,910 | karlseguin/ccache | layeredcache.go | GetOrCreateSecondaryCache | func (c *LayeredCache) GetOrCreateSecondaryCache(primary string) *SecondaryCache {
primaryBkt := c.bucket(primary)
bkt := primaryBkt.getSecondaryBucket(primary)
primaryBkt.Lock()
if bkt == nil {
bkt = &bucket{lookup: make(map[string]*Item)}
primaryBkt.buckets[primary] = bkt
}
primaryBkt.Unlock()
return &SecondaryCache{
bucket: bkt,
pCache: c,
}
} | go | func (c *LayeredCache) GetOrCreateSecondaryCache(primary string) *SecondaryCache {
primaryBkt := c.bucket(primary)
bkt := primaryBkt.getSecondaryBucket(primary)
primaryBkt.Lock()
if bkt == nil {
bkt = &bucket{lookup: make(map[string]*Item)}
primaryBkt.buckets[primary] = bkt
}
primaryBkt.Unlock()
return &SecondaryCache{
bucket: bkt,
pCache: c,
}
} | [
"func",
"(",
"c",
"*",
"LayeredCache",
")",
"GetOrCreateSecondaryCache",
"(",
"primary",
"string",
")",
"*",
"SecondaryCache",
"{",
"primaryBkt",
":=",
"c",
".",
"bucket",
"(",
"primary",
")",
"\n",
"bkt",
":=",
"primaryBkt",
".",
"getSecondaryBucket",
"(",
... | // Get the secondary cache for a given primary key. This operation will
// never return nil. In the case where the primary key does not exist, a
// new, underlying, empty bucket will be created and returned. | [
"Get",
"the",
"secondary",
"cache",
"for",
"a",
"given",
"primary",
"key",
".",
"This",
"operation",
"will",
"never",
"return",
"nil",
".",
"In",
"the",
"case",
"where",
"the",
"primary",
"key",
"does",
"not",
"exist",
"a",
"new",
"underlying",
"empty",
... | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/layeredcache.go#L78-L91 |
13,911 | karlseguin/ccache | layeredcache.go | Replace | func (c *LayeredCache) Replace(primary, secondary string, value interface{}) bool {
item := c.bucket(primary).get(primary, secondary)
if item == nil {
return false
}
c.Set(primary, secondary, value, item.TTL())
return true
} | go | func (c *LayeredCache) Replace(primary, secondary string, value interface{}) bool {
item := c.bucket(primary).get(primary, secondary)
if item == nil {
return false
}
c.Set(primary, secondary, value, item.TTL())
return true
} | [
"func",
"(",
"c",
"*",
"LayeredCache",
")",
"Replace",
"(",
"primary",
",",
"secondary",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"item",
":=",
"c",
".",
"bucket",
"(",
"primary",
")",
".",
"get",
"(",
"primary",
",",
"seconda... | // Replace the value if it exists, does not set if it doesn't.
// Returns true if the item existed an was replaced, false otherwise.
// Replace does not reset item's TTL nor does it alter its position in the LRU | [
"Replace",
"the",
"value",
"if",
"it",
"exists",
"does",
"not",
"set",
"if",
"it",
"doesn",
"t",
".",
"Returns",
"true",
"if",
"the",
"item",
"existed",
"an",
"was",
"replaced",
"false",
"otherwise",
".",
"Replace",
"does",
"not",
"reset",
"item",
"s",
... | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/layeredcache.go#L112-L119 |
13,912 | karlseguin/ccache | layeredcache.go | Fetch | func (c *LayeredCache) Fetch(primary, secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
item := c.Get(primary, secondary)
if item != nil {
return item, nil
}
value, err := fetch()
if err != nil {
return nil, err
}
return c.set(primary, secondary, value, duration), nil
} | go | func (c *LayeredCache) Fetch(primary, secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
item := c.Get(primary, secondary)
if item != nil {
return item, nil
}
value, err := fetch()
if err != nil {
return nil, err
}
return c.set(primary, secondary, value, duration), nil
} | [
"func",
"(",
"c",
"*",
"LayeredCache",
")",
"Fetch",
"(",
"primary",
",",
"secondary",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"fetch",
"func",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
")",
"(",
"*",
"Item",
",",
"e... | // Attempts to get the value from the cache and calles fetch on a miss.
// If fetch returns an error, no value is cached and the error is returned back
// to the caller. | [
"Attempts",
"to",
"get",
"the",
"value",
"from",
"the",
"cache",
"and",
"calles",
"fetch",
"on",
"a",
"miss",
".",
"If",
"fetch",
"returns",
"an",
"error",
"no",
"value",
"is",
"cached",
"and",
"the",
"error",
"is",
"returned",
"back",
"to",
"the",
"ca... | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/layeredcache.go#L124-L134 |
13,913 | karlseguin/ccache | layeredcache.go | DeleteAll | func (c *LayeredCache) DeleteAll(primary string) bool {
return c.bucket(primary).deleteAll(primary, c.deletables)
} | go | func (c *LayeredCache) DeleteAll(primary string) bool {
return c.bucket(primary).deleteAll(primary, c.deletables)
} | [
"func",
"(",
"c",
"*",
"LayeredCache",
")",
"DeleteAll",
"(",
"primary",
"string",
")",
"bool",
"{",
"return",
"c",
".",
"bucket",
"(",
"primary",
")",
".",
"deleteAll",
"(",
"primary",
",",
"c",
".",
"deletables",
")",
"\n",
"}"
] | // Deletes all items that share the same primary key | [
"Deletes",
"all",
"items",
"that",
"share",
"the",
"same",
"primary",
"key"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/layeredcache.go#L147-L149 |
13,914 | karlseguin/ccache | layeredcache.go | Clear | func (c *LayeredCache) Clear() {
for _, bucket := range c.buckets {
bucket.clear()
}
c.size = 0
c.list = list.New()
} | go | func (c *LayeredCache) Clear() {
for _, bucket := range c.buckets {
bucket.clear()
}
c.size = 0
c.list = list.New()
} | [
"func",
"(",
"c",
"*",
"LayeredCache",
")",
"Clear",
"(",
")",
"{",
"for",
"_",
",",
"bucket",
":=",
"range",
"c",
".",
"buckets",
"{",
"bucket",
".",
"clear",
"(",
")",
"\n",
"}",
"\n",
"c",
".",
"size",
"=",
"0",
"\n",
"c",
".",
"list",
"="... | //this isn't thread safe. It's meant to be called from non-concurrent tests | [
"this",
"isn",
"t",
"thread",
"safe",
".",
"It",
"s",
"meant",
"to",
"be",
"called",
"from",
"non",
"-",
"concurrent",
"tests"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/layeredcache.go#L152-L158 |
13,915 | karlseguin/ccache | cache.go | Replace | func (c *Cache) Replace(key string, value interface{}) bool {
item := c.bucket(key).get(key)
if item == nil {
return false
}
c.Set(key, value, item.TTL())
return true
} | go | func (c *Cache) Replace(key string, value interface{}) bool {
item := c.bucket(key).get(key)
if item == nil {
return false
}
c.Set(key, value, item.TTL())
return true
} | [
"func",
"(",
"c",
"*",
"Cache",
")",
"Replace",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"item",
":=",
"c",
".",
"bucket",
"(",
"key",
")",
".",
"get",
"(",
"key",
")",
"\n",
"if",
"item",
"==",
"nil",
"{",
... | // Replace the value if it exists, does not set if it doesn't.
// Returns true if the item existed an was replaced, false otherwise.
// Replace does not reset item's TTL | [
"Replace",
"the",
"value",
"if",
"it",
"exists",
"does",
"not",
"set",
"if",
"it",
"doesn",
"t",
".",
"Returns",
"true",
"if",
"the",
"item",
"existed",
"an",
"was",
"replaced",
"false",
"otherwise",
".",
"Replace",
"does",
"not",
"reset",
"item",
"s",
... | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/cache.go#L82-L89 |
13,916 | karlseguin/ccache | secondarycache.go | Get | func (s *SecondaryCache) Get(secondary string) *Item {
return s.bucket.get(secondary)
} | go | func (s *SecondaryCache) Get(secondary string) *Item {
return s.bucket.get(secondary)
} | [
"func",
"(",
"s",
"*",
"SecondaryCache",
")",
"Get",
"(",
"secondary",
"string",
")",
"*",
"Item",
"{",
"return",
"s",
".",
"bucket",
".",
"get",
"(",
"secondary",
")",
"\n",
"}"
] | // Get the secondary key.
// The semantics are the same as for LayeredCache.Get | [
"Get",
"the",
"secondary",
"key",
".",
"The",
"semantics",
"are",
"the",
"same",
"as",
"for",
"LayeredCache",
".",
"Get"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/secondarycache.go#L12-L14 |
13,917 | karlseguin/ccache | secondarycache.go | Set | func (s *SecondaryCache) Set(secondary string, value interface{}, duration time.Duration) *Item {
item, existing := s.bucket.set(secondary, value, duration)
if existing != nil {
s.pCache.deletables <- existing
}
s.pCache.promote(item)
return item
} | go | func (s *SecondaryCache) Set(secondary string, value interface{}, duration time.Duration) *Item {
item, existing := s.bucket.set(secondary, value, duration)
if existing != nil {
s.pCache.deletables <- existing
}
s.pCache.promote(item)
return item
} | [
"func",
"(",
"s",
"*",
"SecondaryCache",
")",
"Set",
"(",
"secondary",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"duration",
"time",
".",
"Duration",
")",
"*",
"Item",
"{",
"item",
",",
"existing",
":=",
"s",
".",
"bucket",
".",
"set",
"(",... | // Set the secondary key to a value.
// The semantics are the same as for LayeredCache.Set | [
"Set",
"the",
"secondary",
"key",
"to",
"a",
"value",
".",
"The",
"semantics",
"are",
"the",
"same",
"as",
"for",
"LayeredCache",
".",
"Set"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/secondarycache.go#L18-L25 |
13,918 | karlseguin/ccache | secondarycache.go | Fetch | func (s *SecondaryCache) Fetch(secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
item := s.Get(secondary)
if item != nil {
return item, nil
}
value, err := fetch()
if err != nil {
return nil, err
}
return s.Set(secondary, value, duration), nil
} | go | func (s *SecondaryCache) Fetch(secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
item := s.Get(secondary)
if item != nil {
return item, nil
}
value, err := fetch()
if err != nil {
return nil, err
}
return s.Set(secondary, value, duration), nil
} | [
"func",
"(",
"s",
"*",
"SecondaryCache",
")",
"Fetch",
"(",
"secondary",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"fetch",
"func",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
")",
"(",
"*",
"Item",
",",
"error",
")",
"{... | // Fetch or set a secondary key.
// The semantics are the same as for LayeredCache.Fetch | [
"Fetch",
"or",
"set",
"a",
"secondary",
"key",
".",
"The",
"semantics",
"are",
"the",
"same",
"as",
"for",
"LayeredCache",
".",
"Fetch"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/secondarycache.go#L29-L39 |
13,919 | karlseguin/ccache | secondarycache.go | Delete | func (s *SecondaryCache) Delete(secondary string) bool {
item := s.bucket.delete(secondary)
if item != nil {
s.pCache.deletables <- item
return true
}
return false
} | go | func (s *SecondaryCache) Delete(secondary string) bool {
item := s.bucket.delete(secondary)
if item != nil {
s.pCache.deletables <- item
return true
}
return false
} | [
"func",
"(",
"s",
"*",
"SecondaryCache",
")",
"Delete",
"(",
"secondary",
"string",
")",
"bool",
"{",
"item",
":=",
"s",
".",
"bucket",
".",
"delete",
"(",
"secondary",
")",
"\n",
"if",
"item",
"!=",
"nil",
"{",
"s",
".",
"pCache",
".",
"deletables",... | // Delete a secondary key.
// The semantics are the same as for LayeredCache.Delete | [
"Delete",
"a",
"secondary",
"key",
".",
"The",
"semantics",
"are",
"the",
"same",
"as",
"for",
"LayeredCache",
".",
"Delete"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/secondarycache.go#L43-L50 |
13,920 | karlseguin/ccache | secondarycache.go | Replace | func (s *SecondaryCache) Replace(secondary string, value interface{}) bool {
item := s.Get(secondary)
if item == nil {
return false
}
s.Set(secondary, value, item.TTL())
return true
} | go | func (s *SecondaryCache) Replace(secondary string, value interface{}) bool {
item := s.Get(secondary)
if item == nil {
return false
}
s.Set(secondary, value, item.TTL())
return true
} | [
"func",
"(",
"s",
"*",
"SecondaryCache",
")",
"Replace",
"(",
"secondary",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"item",
":=",
"s",
".",
"Get",
"(",
"secondary",
")",
"\n",
"if",
"item",
"==",
"nil",
"{",
"return",
"false",... | // Replace a secondary key.
// The semantics are the same as for LayeredCache.Replace | [
"Replace",
"a",
"secondary",
"key",
".",
"The",
"semantics",
"are",
"the",
"same",
"as",
"for",
"LayeredCache",
".",
"Replace"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/secondarycache.go#L54-L61 |
13,921 | karlseguin/ccache | secondarycache.go | TrackingGet | func (c *SecondaryCache) TrackingGet(secondary string) TrackedItem {
item := c.Get(secondary)
if item == nil {
return NilTracked
}
item.track()
return item
} | go | func (c *SecondaryCache) TrackingGet(secondary string) TrackedItem {
item := c.Get(secondary)
if item == nil {
return NilTracked
}
item.track()
return item
} | [
"func",
"(",
"c",
"*",
"SecondaryCache",
")",
"TrackingGet",
"(",
"secondary",
"string",
")",
"TrackedItem",
"{",
"item",
":=",
"c",
".",
"Get",
"(",
"secondary",
")",
"\n",
"if",
"item",
"==",
"nil",
"{",
"return",
"NilTracked",
"\n",
"}",
"\n",
"item... | // Track a secondary key.
// The semantics are the same as for LayeredCache.TrackingGet | [
"Track",
"a",
"secondary",
"key",
".",
"The",
"semantics",
"are",
"the",
"same",
"as",
"for",
"LayeredCache",
".",
"TrackingGet"
] | ec06cd93a07565b373789b0078ba88fe697fddd9 | https://github.com/karlseguin/ccache/blob/ec06cd93a07565b373789b0078ba88fe697fddd9/secondarycache.go#L65-L72 |
13,922 | fullsailor/pkcs7 | pkcs7.go | Parse | func Parse(data []byte) (p7 *PKCS7, err error) {
if len(data) == 0 {
return nil, errors.New("pkcs7: input data is empty")
}
var info contentInfo
der, err := ber2der(data)
if err != nil {
return nil, err
}
rest, err := asn1.Unmarshal(der, &info)
if len(rest) > 0 {
err = asn1.SyntaxError{Msg: "trailing data"}
return
}
if err != nil {
return
}
// fmt.Printf("--> Content Type: %s", info.ContentType)
switch {
case info.ContentType.Equal(oidSignedData):
return parseSignedData(info.Content.Bytes)
case info.ContentType.Equal(oidEnvelopedData):
return parseEnvelopedData(info.Content.Bytes)
}
return nil, ErrUnsupportedContentType
} | go | func Parse(data []byte) (p7 *PKCS7, err error) {
if len(data) == 0 {
return nil, errors.New("pkcs7: input data is empty")
}
var info contentInfo
der, err := ber2der(data)
if err != nil {
return nil, err
}
rest, err := asn1.Unmarshal(der, &info)
if len(rest) > 0 {
err = asn1.SyntaxError{Msg: "trailing data"}
return
}
if err != nil {
return
}
// fmt.Printf("--> Content Type: %s", info.ContentType)
switch {
case info.ContentType.Equal(oidSignedData):
return parseSignedData(info.Content.Bytes)
case info.ContentType.Equal(oidEnvelopedData):
return parseEnvelopedData(info.Content.Bytes)
}
return nil, ErrUnsupportedContentType
} | [
"func",
"Parse",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"p7",
"*",
"PKCS7",
",",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"... | // Parse decodes a DER encoded PKCS7 package | [
"Parse",
"decodes",
"a",
"DER",
"encoded",
"PKCS7",
"package"
] | d7302db945fa6ea264fb79d8e13e931ea514a602 | https://github.com/fullsailor/pkcs7/blob/d7302db945fa6ea264fb79d8e13e931ea514a602/pkcs7.go#L122-L148 |
13,923 | fullsailor/pkcs7 | pkcs7.go | GetOnlySigner | func (p7 *PKCS7) GetOnlySigner() *x509.Certificate {
if len(p7.Signers) != 1 {
return nil
}
signer := p7.Signers[0]
return getCertFromCertsByIssuerAndSerial(p7.Certificates, signer.IssuerAndSerialNumber)
} | go | func (p7 *PKCS7) GetOnlySigner() *x509.Certificate {
if len(p7.Signers) != 1 {
return nil
}
signer := p7.Signers[0]
return getCertFromCertsByIssuerAndSerial(p7.Certificates, signer.IssuerAndSerialNumber)
} | [
"func",
"(",
"p7",
"*",
"PKCS7",
")",
"GetOnlySigner",
"(",
")",
"*",
"x509",
".",
"Certificate",
"{",
"if",
"len",
"(",
"p7",
".",
"Signers",
")",
"!=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"signer",
":=",
"p7",
".",
"Signers",
"[",
"0",
... | // GetOnlySigner returns an x509.Certificate for the first signer of the signed
// data payload. If there are more or less than one signer, nil is returned | [
"GetOnlySigner",
"returns",
"an",
"x509",
".",
"Certificate",
"for",
"the",
"first",
"signer",
"of",
"the",
"signed",
"data",
"payload",
".",
"If",
"there",
"are",
"more",
"or",
"less",
"than",
"one",
"signer",
"nil",
"is",
"returned"
] | d7302db945fa6ea264fb79d8e13e931ea514a602 | https://github.com/fullsailor/pkcs7/blob/d7302db945fa6ea264fb79d8e13e931ea514a602/pkcs7.go#L321-L327 |
13,924 | fullsailor/pkcs7 | pkcs7.go | Decrypt | func (p7 *PKCS7) Decrypt(cert *x509.Certificate, pk crypto.PrivateKey) ([]byte, error) {
data, ok := p7.raw.(envelopedData)
if !ok {
return nil, ErrNotEncryptedContent
}
recipient := selectRecipientForCertificate(data.RecipientInfos, cert)
if recipient.EncryptedKey == nil {
return nil, errors.New("pkcs7: no enveloped recipient for provided certificate")
}
if priv := pk.(*rsa.PrivateKey); priv != nil {
var contentKey []byte
contentKey, err := rsa.DecryptPKCS1v15(rand.Reader, priv, recipient.EncryptedKey)
if err != nil {
return nil, err
}
return data.EncryptedContentInfo.decrypt(contentKey)
}
fmt.Printf("Unsupported Private Key: %v\n", pk)
return nil, ErrUnsupportedAlgorithm
} | go | func (p7 *PKCS7) Decrypt(cert *x509.Certificate, pk crypto.PrivateKey) ([]byte, error) {
data, ok := p7.raw.(envelopedData)
if !ok {
return nil, ErrNotEncryptedContent
}
recipient := selectRecipientForCertificate(data.RecipientInfos, cert)
if recipient.EncryptedKey == nil {
return nil, errors.New("pkcs7: no enveloped recipient for provided certificate")
}
if priv := pk.(*rsa.PrivateKey); priv != nil {
var contentKey []byte
contentKey, err := rsa.DecryptPKCS1v15(rand.Reader, priv, recipient.EncryptedKey)
if err != nil {
return nil, err
}
return data.EncryptedContentInfo.decrypt(contentKey)
}
fmt.Printf("Unsupported Private Key: %v\n", pk)
return nil, ErrUnsupportedAlgorithm
} | [
"func",
"(",
"p7",
"*",
"PKCS7",
")",
"Decrypt",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
",",
"pk",
"crypto",
".",
"PrivateKey",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"ok",
":=",
"p7",
".",
"raw",
".",
"(",
"env... | // Decrypt decrypts encrypted content info for recipient cert and private key | [
"Decrypt",
"decrypts",
"encrypted",
"content",
"info",
"for",
"recipient",
"cert",
"and",
"private",
"key"
] | d7302db945fa6ea264fb79d8e13e931ea514a602 | https://github.com/fullsailor/pkcs7/blob/d7302db945fa6ea264fb79d8e13e931ea514a602/pkcs7.go#L336-L355 |
13,925 | fullsailor/pkcs7 | pkcs7.go | AddSigner | func (sd *SignedData) AddSigner(cert *x509.Certificate, pkey crypto.PrivateKey, config SignerInfoConfig) error {
attrs := &attributes{}
attrs.Add(oidAttributeContentType, sd.sd.ContentInfo.ContentType)
attrs.Add(oidAttributeMessageDigest, sd.messageDigest)
attrs.Add(oidAttributeSigningTime, time.Now())
for _, attr := range config.ExtraSignedAttributes {
attrs.Add(attr.Type, attr.Value)
}
finalAttrs, err := attrs.ForMarshaling()
if err != nil {
return err
}
signature, err := signAttributes(finalAttrs, pkey, crypto.SHA1)
if err != nil {
return err
}
ias, err := cert2issuerAndSerial(cert)
if err != nil {
return err
}
signer := signerInfo{
AuthenticatedAttributes: finalAttrs,
DigestAlgorithm: pkix.AlgorithmIdentifier{Algorithm: oidDigestAlgorithmSHA1},
DigestEncryptionAlgorithm: pkix.AlgorithmIdentifier{Algorithm: oidSignatureSHA1WithRSA},
IssuerAndSerialNumber: ias,
EncryptedDigest: signature,
Version: 1,
}
// create signature of signed attributes
sd.certs = append(sd.certs, cert)
sd.sd.SignerInfos = append(sd.sd.SignerInfos, signer)
return nil
} | go | func (sd *SignedData) AddSigner(cert *x509.Certificate, pkey crypto.PrivateKey, config SignerInfoConfig) error {
attrs := &attributes{}
attrs.Add(oidAttributeContentType, sd.sd.ContentInfo.ContentType)
attrs.Add(oidAttributeMessageDigest, sd.messageDigest)
attrs.Add(oidAttributeSigningTime, time.Now())
for _, attr := range config.ExtraSignedAttributes {
attrs.Add(attr.Type, attr.Value)
}
finalAttrs, err := attrs.ForMarshaling()
if err != nil {
return err
}
signature, err := signAttributes(finalAttrs, pkey, crypto.SHA1)
if err != nil {
return err
}
ias, err := cert2issuerAndSerial(cert)
if err != nil {
return err
}
signer := signerInfo{
AuthenticatedAttributes: finalAttrs,
DigestAlgorithm: pkix.AlgorithmIdentifier{Algorithm: oidDigestAlgorithmSHA1},
DigestEncryptionAlgorithm: pkix.AlgorithmIdentifier{Algorithm: oidSignatureSHA1WithRSA},
IssuerAndSerialNumber: ias,
EncryptedDigest: signature,
Version: 1,
}
// create signature of signed attributes
sd.certs = append(sd.certs, cert)
sd.sd.SignerInfos = append(sd.sd.SignerInfos, signer)
return nil
} | [
"func",
"(",
"sd",
"*",
"SignedData",
")",
"AddSigner",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
",",
"pkey",
"crypto",
".",
"PrivateKey",
",",
"config",
"SignerInfoConfig",
")",
"error",
"{",
"attrs",
":=",
"&",
"attributes",
"{",
"}",
"\n",
"attrs... | // AddSigner signs attributes about the content and adds certificate to payload | [
"AddSigner",
"signs",
"attributes",
"about",
"the",
"content",
"and",
"adds",
"certificate",
"to",
"payload"
] | d7302db945fa6ea264fb79d8e13e931ea514a602 | https://github.com/fullsailor/pkcs7/blob/d7302db945fa6ea264fb79d8e13e931ea514a602/pkcs7.go#L633-L667 |
13,926 | fullsailor/pkcs7 | pkcs7.go | AddCertificate | func (sd *SignedData) AddCertificate(cert *x509.Certificate) {
sd.certs = append(sd.certs, cert)
} | go | func (sd *SignedData) AddCertificate(cert *x509.Certificate) {
sd.certs = append(sd.certs, cert)
} | [
"func",
"(",
"sd",
"*",
"SignedData",
")",
"AddCertificate",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
")",
"{",
"sd",
".",
"certs",
"=",
"append",
"(",
"sd",
".",
"certs",
",",
"cert",
")",
"\n",
"}"
] | // AddCertificate adds the certificate to the payload. Useful for parent certificates | [
"AddCertificate",
"adds",
"the",
"certificate",
"to",
"the",
"payload",
".",
"Useful",
"for",
"parent",
"certificates"
] | d7302db945fa6ea264fb79d8e13e931ea514a602 | https://github.com/fullsailor/pkcs7/blob/d7302db945fa6ea264fb79d8e13e931ea514a602/pkcs7.go#L670-L672 |
13,927 | fzipp/gocyclo | gocyclo.go | complexity | func complexity(fn *ast.FuncDecl) int {
v := complexityVisitor{}
ast.Walk(&v, fn)
return v.Complexity
} | go | func complexity(fn *ast.FuncDecl) int {
v := complexityVisitor{}
ast.Walk(&v, fn)
return v.Complexity
} | [
"func",
"complexity",
"(",
"fn",
"*",
"ast",
".",
"FuncDecl",
")",
"int",
"{",
"v",
":=",
"complexityVisitor",
"{",
"}",
"\n",
"ast",
".",
"Walk",
"(",
"&",
"v",
",",
"fn",
")",
"\n",
"return",
"v",
".",
"Complexity",
"\n",
"}"
] | // complexity calculates the cyclomatic complexity of a function. | [
"complexity",
"calculates",
"the",
"cyclomatic",
"complexity",
"of",
"a",
"function",
"."
] | 6acd4345c835499920e8426c7e4e8d7a34f1bb83 | https://github.com/fzipp/gocyclo/blob/6acd4345c835499920e8426c7e4e8d7a34f1bb83/gocyclo.go#L203-L207 |
13,928 | go-testfixtures/testfixtures | generate.go | GenerateFixtures | func GenerateFixtures(db *sql.DB, helper Helper, dir string) error {
tables, err := helper.tableNames(db)
if err != nil {
return err
}
for _, table := range tables {
filename := path.Join(dir, table+".yml")
if err := generateFixturesForTable(db, helper, &TableInfo{Name: table}, filename); err != nil {
return err
}
}
return nil
} | go | func GenerateFixtures(db *sql.DB, helper Helper, dir string) error {
tables, err := helper.tableNames(db)
if err != nil {
return err
}
for _, table := range tables {
filename := path.Join(dir, table+".yml")
if err := generateFixturesForTable(db, helper, &TableInfo{Name: table}, filename); err != nil {
return err
}
}
return nil
} | [
"func",
"GenerateFixtures",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"helper",
"Helper",
",",
"dir",
"string",
")",
"error",
"{",
"tables",
",",
"err",
":=",
"helper",
".",
"tableNames",
"(",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // GenerateFixtures generates fixtures for the current contents of a database, and saves
// them to the specified directory | [
"GenerateFixtures",
"generates",
"fixtures",
"for",
"the",
"current",
"contents",
"of",
"a",
"database",
"and",
"saves",
"them",
"to",
"the",
"specified",
"directory"
] | fa9509ec9b56cd2c734b2c302341932acc726c3c | https://github.com/go-testfixtures/testfixtures/blob/fa9509ec9b56cd2c734b2c302341932acc726c3c/generate.go#L28-L40 |
13,929 | go-ozzo/ozzo-dbx | select.go | NewSelectQuery | func NewSelectQuery(builder Builder, db *DB) *SelectQuery {
return &SelectQuery{
builder: builder,
selects: []string{},
from: []string{},
join: []JoinInfo{},
orderBy: []string{},
groupBy: []string{},
union: []UnionInfo{},
limit: -1,
params: Params{},
FieldMapper: db.FieldMapper,
}
} | go | func NewSelectQuery(builder Builder, db *DB) *SelectQuery {
return &SelectQuery{
builder: builder,
selects: []string{},
from: []string{},
join: []JoinInfo{},
orderBy: []string{},
groupBy: []string{},
union: []UnionInfo{},
limit: -1,
params: Params{},
FieldMapper: db.FieldMapper,
}
} | [
"func",
"NewSelectQuery",
"(",
"builder",
"Builder",
",",
"db",
"*",
"DB",
")",
"*",
"SelectQuery",
"{",
"return",
"&",
"SelectQuery",
"{",
"builder",
":",
"builder",
",",
"selects",
":",
"[",
"]",
"string",
"{",
"}",
",",
"from",
":",
"[",
"]",
"str... | // NewSelectQuery creates a new SelectQuery instance. | [
"NewSelectQuery",
"creates",
"a",
"new",
"SelectQuery",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L49-L62 |
13,930 | go-ozzo/ozzo-dbx | select.go | Select | func (s *SelectQuery) Select(cols ...string) *SelectQuery {
s.selects = cols
return s
} | go | func (s *SelectQuery) Select(cols ...string) *SelectQuery {
s.selects = cols
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Select",
"(",
"cols",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"selects",
"=",
"cols",
"\n",
"return",
"s",
"\n",
"}"
] | // Select specifies the columns to be selected.
// Column names will be automatically quoted. | [
"Select",
"specifies",
"the",
"columns",
"to",
"be",
"selected",
".",
"Column",
"names",
"will",
"be",
"automatically",
"quoted",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L66-L69 |
13,931 | go-ozzo/ozzo-dbx | select.go | AndSelect | func (s *SelectQuery) AndSelect(cols ...string) *SelectQuery {
s.selects = append(s.selects, cols...)
return s
} | go | func (s *SelectQuery) AndSelect(cols ...string) *SelectQuery {
s.selects = append(s.selects, cols...)
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"AndSelect",
"(",
"cols",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"selects",
"=",
"append",
"(",
"s",
".",
"selects",
",",
"cols",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // AndSelect adds additional columns to be selected.
// Column names will be automatically quoted. | [
"AndSelect",
"adds",
"additional",
"columns",
"to",
"be",
"selected",
".",
"Column",
"names",
"will",
"be",
"automatically",
"quoted",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L73-L76 |
13,932 | go-ozzo/ozzo-dbx | select.go | Distinct | func (s *SelectQuery) Distinct(v bool) *SelectQuery {
s.distinct = v
return s
} | go | func (s *SelectQuery) Distinct(v bool) *SelectQuery {
s.distinct = v
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Distinct",
"(",
"v",
"bool",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"distinct",
"=",
"v",
"\n",
"return",
"s",
"\n",
"}"
] | // Distinct specifies whether to select columns distinctively.
// By default, distinct is false. | [
"Distinct",
"specifies",
"whether",
"to",
"select",
"columns",
"distinctively",
".",
"By",
"default",
"distinct",
"is",
"false",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L80-L83 |
13,933 | go-ozzo/ozzo-dbx | select.go | SelectOption | func (s *SelectQuery) SelectOption(option string) *SelectQuery {
s.selectOption = option
return s
} | go | func (s *SelectQuery) SelectOption(option string) *SelectQuery {
s.selectOption = option
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"SelectOption",
"(",
"option",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"selectOption",
"=",
"option",
"\n",
"return",
"s",
"\n",
"}"
] | // SelectOption specifies additional option that should be append to "SELECT". | [
"SelectOption",
"specifies",
"additional",
"option",
"that",
"should",
"be",
"append",
"to",
"SELECT",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L86-L89 |
13,934 | go-ozzo/ozzo-dbx | select.go | From | func (s *SelectQuery) From(tables ...string) *SelectQuery {
s.from = tables
return s
} | go | func (s *SelectQuery) From(tables ...string) *SelectQuery {
s.from = tables
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"From",
"(",
"tables",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"from",
"=",
"tables",
"\n",
"return",
"s",
"\n",
"}"
] | // From specifies which tables to select from.
// Table names will be automatically quoted. | [
"From",
"specifies",
"which",
"tables",
"to",
"select",
"from",
".",
"Table",
"names",
"will",
"be",
"automatically",
"quoted",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L93-L96 |
13,935 | go-ozzo/ozzo-dbx | select.go | Where | func (s *SelectQuery) Where(e Expression) *SelectQuery {
s.where = e
return s
} | go | func (s *SelectQuery) Where(e Expression) *SelectQuery {
s.where = e
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Where",
"(",
"e",
"Expression",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"where",
"=",
"e",
"\n",
"return",
"s",
"\n",
"}"
] | // Where specifies the WHERE condition. | [
"Where",
"specifies",
"the",
"WHERE",
"condition",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L99-L102 |
13,936 | go-ozzo/ozzo-dbx | select.go | InnerJoin | func (s *SelectQuery) InnerJoin(table string, on Expression) *SelectQuery {
return s.Join("INNER JOIN", table, on)
} | go | func (s *SelectQuery) InnerJoin(table string, on Expression) *SelectQuery {
return s.Join("INNER JOIN", table, on)
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"InnerJoin",
"(",
"table",
"string",
",",
"on",
"Expression",
")",
"*",
"SelectQuery",
"{",
"return",
"s",
".",
"Join",
"(",
"\"",
"\"",
",",
"table",
",",
"on",
")",
"\n",
"}"
] | // InnerJoin specifies an INNER JOIN clause.
// This is a shortcut method for Join. | [
"InnerJoin",
"specifies",
"an",
"INNER",
"JOIN",
"clause",
".",
"This",
"is",
"a",
"shortcut",
"method",
"for",
"Join",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L125-L127 |
13,937 | go-ozzo/ozzo-dbx | select.go | LeftJoin | func (s *SelectQuery) LeftJoin(table string, on Expression) *SelectQuery {
return s.Join("LEFT JOIN", table, on)
} | go | func (s *SelectQuery) LeftJoin(table string, on Expression) *SelectQuery {
return s.Join("LEFT JOIN", table, on)
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"LeftJoin",
"(",
"table",
"string",
",",
"on",
"Expression",
")",
"*",
"SelectQuery",
"{",
"return",
"s",
".",
"Join",
"(",
"\"",
"\"",
",",
"table",
",",
"on",
")",
"\n",
"}"
] | // LeftJoin specifies a LEFT JOIN clause.
// This is a shortcut method for Join. | [
"LeftJoin",
"specifies",
"a",
"LEFT",
"JOIN",
"clause",
".",
"This",
"is",
"a",
"shortcut",
"method",
"for",
"Join",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L131-L133 |
13,938 | go-ozzo/ozzo-dbx | select.go | RightJoin | func (s *SelectQuery) RightJoin(table string, on Expression) *SelectQuery {
return s.Join("RIGHT JOIN", table, on)
} | go | func (s *SelectQuery) RightJoin(table string, on Expression) *SelectQuery {
return s.Join("RIGHT JOIN", table, on)
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"RightJoin",
"(",
"table",
"string",
",",
"on",
"Expression",
")",
"*",
"SelectQuery",
"{",
"return",
"s",
".",
"Join",
"(",
"\"",
"\"",
",",
"table",
",",
"on",
")",
"\n",
"}"
] | // RightJoin specifies a RIGHT JOIN clause.
// This is a shortcut method for Join. | [
"RightJoin",
"specifies",
"a",
"RIGHT",
"JOIN",
"clause",
".",
"This",
"is",
"a",
"shortcut",
"method",
"for",
"Join",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L137-L139 |
13,939 | go-ozzo/ozzo-dbx | select.go | OrderBy | func (s *SelectQuery) OrderBy(cols ...string) *SelectQuery {
s.orderBy = cols
return s
} | go | func (s *SelectQuery) OrderBy(cols ...string) *SelectQuery {
s.orderBy = cols
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"OrderBy",
"(",
"cols",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"orderBy",
"=",
"cols",
"\n",
"return",
"s",
"\n",
"}"
] | // OrderBy specifies the ORDER BY clause.
// Column names will be properly quoted. A column name can contain "ASC" or "DESC" to indicate its ordering direction. | [
"OrderBy",
"specifies",
"the",
"ORDER",
"BY",
"clause",
".",
"Column",
"names",
"will",
"be",
"properly",
"quoted",
".",
"A",
"column",
"name",
"can",
"contain",
"ASC",
"or",
"DESC",
"to",
"indicate",
"its",
"ordering",
"direction",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L143-L146 |
13,940 | go-ozzo/ozzo-dbx | select.go | AndOrderBy | func (s *SelectQuery) AndOrderBy(cols ...string) *SelectQuery {
s.orderBy = append(s.orderBy, cols...)
return s
} | go | func (s *SelectQuery) AndOrderBy(cols ...string) *SelectQuery {
s.orderBy = append(s.orderBy, cols...)
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"AndOrderBy",
"(",
"cols",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"orderBy",
"=",
"append",
"(",
"s",
".",
"orderBy",
",",
"cols",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // AndOrderBy appends additional columns to the existing ORDER BY clause.
// Column names will be properly quoted. A column name can contain "ASC" or "DESC" to indicate its ordering direction. | [
"AndOrderBy",
"appends",
"additional",
"columns",
"to",
"the",
"existing",
"ORDER",
"BY",
"clause",
".",
"Column",
"names",
"will",
"be",
"properly",
"quoted",
".",
"A",
"column",
"name",
"can",
"contain",
"ASC",
"or",
"DESC",
"to",
"indicate",
"its",
"order... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L150-L153 |
13,941 | go-ozzo/ozzo-dbx | select.go | GroupBy | func (s *SelectQuery) GroupBy(cols ...string) *SelectQuery {
s.groupBy = cols
return s
} | go | func (s *SelectQuery) GroupBy(cols ...string) *SelectQuery {
s.groupBy = cols
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"GroupBy",
"(",
"cols",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"groupBy",
"=",
"cols",
"\n",
"return",
"s",
"\n",
"}"
] | // GroupBy specifies the GROUP BY clause.
// Column names will be properly quoted. | [
"GroupBy",
"specifies",
"the",
"GROUP",
"BY",
"clause",
".",
"Column",
"names",
"will",
"be",
"properly",
"quoted",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L157-L160 |
13,942 | go-ozzo/ozzo-dbx | select.go | AndGroupBy | func (s *SelectQuery) AndGroupBy(cols ...string) *SelectQuery {
s.groupBy = append(s.groupBy, cols...)
return s
} | go | func (s *SelectQuery) AndGroupBy(cols ...string) *SelectQuery {
s.groupBy = append(s.groupBy, cols...)
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"AndGroupBy",
"(",
"cols",
"...",
"string",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"groupBy",
"=",
"append",
"(",
"s",
".",
"groupBy",
",",
"cols",
"...",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // AndGroupBy appends additional columns to the existing GROUP BY clause.
// Column names will be properly quoted. | [
"AndGroupBy",
"appends",
"additional",
"columns",
"to",
"the",
"existing",
"GROUP",
"BY",
"clause",
".",
"Column",
"names",
"will",
"be",
"properly",
"quoted",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L164-L167 |
13,943 | go-ozzo/ozzo-dbx | select.go | Having | func (s *SelectQuery) Having(e Expression) *SelectQuery {
s.having = e
return s
} | go | func (s *SelectQuery) Having(e Expression) *SelectQuery {
s.having = e
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Having",
"(",
"e",
"Expression",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"having",
"=",
"e",
"\n",
"return",
"s",
"\n",
"}"
] | // Having specifies the HAVING clause. | [
"Having",
"specifies",
"the",
"HAVING",
"clause",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L170-L173 |
13,944 | go-ozzo/ozzo-dbx | select.go | Union | func (s *SelectQuery) Union(q *Query) *SelectQuery {
s.union = append(s.union, UnionInfo{false, q})
return s
} | go | func (s *SelectQuery) Union(q *Query) *SelectQuery {
s.union = append(s.union, UnionInfo{false, q})
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Union",
"(",
"q",
"*",
"Query",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"union",
"=",
"append",
"(",
"s",
".",
"union",
",",
"UnionInfo",
"{",
"false",
",",
"q",
"}",
")",
"\n",
"return",
"s",
"\n",
"... | // Union specifies a UNION clause. | [
"Union",
"specifies",
"a",
"UNION",
"clause",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L188-L191 |
13,945 | go-ozzo/ozzo-dbx | select.go | UnionAll | func (s *SelectQuery) UnionAll(q *Query) *SelectQuery {
s.union = append(s.union, UnionInfo{true, q})
return s
} | go | func (s *SelectQuery) UnionAll(q *Query) *SelectQuery {
s.union = append(s.union, UnionInfo{true, q})
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"UnionAll",
"(",
"q",
"*",
"Query",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"union",
"=",
"append",
"(",
"s",
".",
"union",
",",
"UnionInfo",
"{",
"true",
",",
"q",
"}",
")",
"\n",
"return",
"s",
"\n",
... | // UnionAll specifies a UNION ALL clause. | [
"UnionAll",
"specifies",
"a",
"UNION",
"ALL",
"clause",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L194-L197 |
13,946 | go-ozzo/ozzo-dbx | select.go | Limit | func (s *SelectQuery) Limit(limit int64) *SelectQuery {
s.limit = limit
return s
} | go | func (s *SelectQuery) Limit(limit int64) *SelectQuery {
s.limit = limit
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Limit",
"(",
"limit",
"int64",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"limit",
"=",
"limit",
"\n",
"return",
"s",
"\n",
"}"
] | // Limit specifies the LIMIT clause.
// A negative limit means no limit. | [
"Limit",
"specifies",
"the",
"LIMIT",
"clause",
".",
"A",
"negative",
"limit",
"means",
"no",
"limit",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L201-L204 |
13,947 | go-ozzo/ozzo-dbx | select.go | Offset | func (s *SelectQuery) Offset(offset int64) *SelectQuery {
s.offset = offset
return s
} | go | func (s *SelectQuery) Offset(offset int64) *SelectQuery {
s.offset = offset
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Offset",
"(",
"offset",
"int64",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"offset",
"=",
"offset",
"\n",
"return",
"s",
"\n",
"}"
] | // Offset specifies the OFFSET clause.
// A negative offset means no offset. | [
"Offset",
"specifies",
"the",
"OFFSET",
"clause",
".",
"A",
"negative",
"offset",
"means",
"no",
"offset",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L208-L211 |
13,948 | go-ozzo/ozzo-dbx | select.go | Bind | func (s *SelectQuery) Bind(params Params) *SelectQuery {
s.params = params
return s
} | go | func (s *SelectQuery) Bind(params Params) *SelectQuery {
s.params = params
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Bind",
"(",
"params",
"Params",
")",
"*",
"SelectQuery",
"{",
"s",
".",
"params",
"=",
"params",
"\n",
"return",
"s",
"\n",
"}"
] | // Bind specifies the parameter values to be bound to the query. | [
"Bind",
"specifies",
"the",
"parameter",
"values",
"to",
"be",
"bound",
"to",
"the",
"query",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L214-L217 |
13,949 | go-ozzo/ozzo-dbx | select.go | AndBind | func (s *SelectQuery) AndBind(params Params) *SelectQuery {
if len(s.params) == 0 {
s.params = params
} else {
for k, v := range params {
s.params[k] = v
}
}
return s
} | go | func (s *SelectQuery) AndBind(params Params) *SelectQuery {
if len(s.params) == 0 {
s.params = params
} else {
for k, v := range params {
s.params[k] = v
}
}
return s
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"AndBind",
"(",
"params",
"Params",
")",
"*",
"SelectQuery",
"{",
"if",
"len",
"(",
"s",
".",
"params",
")",
"==",
"0",
"{",
"s",
".",
"params",
"=",
"params",
"\n",
"}",
"else",
"{",
"for",
"k",
",",
... | // AndBind appends additional parameters to be bound to the query. | [
"AndBind",
"appends",
"additional",
"parameters",
"to",
"be",
"bound",
"to",
"the",
"query",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L220-L229 |
13,950 | go-ozzo/ozzo-dbx | select.go | Build | func (s *SelectQuery) Build() *Query {
params := Params{}
for k, v := range s.params {
params[k] = v
}
qb := s.builder.QueryBuilder()
clauses := []string{
qb.BuildSelect(s.selects, s.distinct, s.selectOption),
qb.BuildFrom(s.from),
qb.BuildJoin(s.join, params),
qb.BuildWhere(s.where, params),
qb.BuildGroupBy(s.groupBy),
qb.BuildHaving(s.having, params),
}
sql := ""
for _, clause := range clauses {
if clause != "" {
if sql == "" {
sql = clause
} else {
sql += " " + clause
}
}
}
sql = qb.BuildOrderByAndLimit(sql, s.orderBy, s.limit, s.offset)
if union := qb.BuildUnion(s.union, params); union != "" {
sql = fmt.Sprintf("(%v) %v", sql, union)
}
return s.builder.NewQuery(sql).Bind(params)
} | go | func (s *SelectQuery) Build() *Query {
params := Params{}
for k, v := range s.params {
params[k] = v
}
qb := s.builder.QueryBuilder()
clauses := []string{
qb.BuildSelect(s.selects, s.distinct, s.selectOption),
qb.BuildFrom(s.from),
qb.BuildJoin(s.join, params),
qb.BuildWhere(s.where, params),
qb.BuildGroupBy(s.groupBy),
qb.BuildHaving(s.having, params),
}
sql := ""
for _, clause := range clauses {
if clause != "" {
if sql == "" {
sql = clause
} else {
sql += " " + clause
}
}
}
sql = qb.BuildOrderByAndLimit(sql, s.orderBy, s.limit, s.offset)
if union := qb.BuildUnion(s.union, params); union != "" {
sql = fmt.Sprintf("(%v) %v", sql, union)
}
return s.builder.NewQuery(sql).Bind(params)
} | [
"func",
"(",
"s",
"*",
"SelectQuery",
")",
"Build",
"(",
")",
"*",
"Query",
"{",
"params",
":=",
"Params",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"s",
".",
"params",
"{",
"params",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"qb... | // Build builds the SELECT query and returns an executable Query object. | [
"Build",
"builds",
"the",
"SELECT",
"query",
"and",
"returns",
"an",
"executable",
"Query",
"object",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/select.go#L232-L264 |
13,951 | go-ozzo/ozzo-dbx | builder_pgsql.go | NewPgsqlBuilder | func NewPgsqlBuilder(db *DB, executor Executor) Builder {
return &PgsqlBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | go | func NewPgsqlBuilder(db *DB, executor Executor) Builder {
return &PgsqlBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | [
"func",
"NewPgsqlBuilder",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
")",
"Builder",
"{",
"return",
"&",
"PgsqlBuilder",
"{",
"NewBaseBuilder",
"(",
"db",
",",
"executor",
")",
",",
"NewBaseQueryBuilder",
"(",
"db",
")",
",",
"}",
"\n",
"}"
] | // NewPgsqlBuilder creates a new PgsqlBuilder instance. | [
"NewPgsqlBuilder",
"creates",
"a",
"new",
"PgsqlBuilder",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_pgsql.go#L22-L27 |
13,952 | go-ozzo/ozzo-dbx | query_builder.go | BuildSelect | func (q *BaseQueryBuilder) BuildSelect(cols []string, distinct bool, option string) string {
var s bytes.Buffer
s.WriteString("SELECT ")
if distinct {
s.WriteString("DISTINCT ")
}
if option != "" {
s.WriteString(option)
s.WriteString(" ")
}
if len(cols) == 0 {
s.WriteString("*")
return s.String()
}
for i, col := range cols {
if i > 0 {
s.WriteString(", ")
}
matches := selectRegex.FindStringSubmatch(col)
if len(matches) == 0 {
s.WriteString(q.db.QuoteColumnName(col))
} else {
col := col[:len(col)-len(matches[0])]
alias := matches[1]
s.WriteString(q.db.QuoteColumnName(col) + " AS " + q.db.QuoteSimpleColumnName(alias))
}
}
return s.String()
} | go | func (q *BaseQueryBuilder) BuildSelect(cols []string, distinct bool, option string) string {
var s bytes.Buffer
s.WriteString("SELECT ")
if distinct {
s.WriteString("DISTINCT ")
}
if option != "" {
s.WriteString(option)
s.WriteString(" ")
}
if len(cols) == 0 {
s.WriteString("*")
return s.String()
}
for i, col := range cols {
if i > 0 {
s.WriteString(", ")
}
matches := selectRegex.FindStringSubmatch(col)
if len(matches) == 0 {
s.WriteString(q.db.QuoteColumnName(col))
} else {
col := col[:len(col)-len(matches[0])]
alias := matches[1]
s.WriteString(q.db.QuoteColumnName(col) + " AS " + q.db.QuoteSimpleColumnName(alias))
}
}
return s.String()
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildSelect",
"(",
"cols",
"[",
"]",
"string",
",",
"distinct",
"bool",
",",
"option",
"string",
")",
"string",
"{",
"var",
"s",
"bytes",
".",
"Buffer",
"\n",
"s",
".",
"WriteString",
"(",
"\"",
"\"",
... | // BuildSelect generates a SELECT clause from the given selected column names. | [
"BuildSelect",
"generates",
"a",
"SELECT",
"clause",
"from",
"the",
"given",
"selected",
"column",
"names",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L55-L85 |
13,953 | go-ozzo/ozzo-dbx | query_builder.go | BuildFrom | func (q *BaseQueryBuilder) BuildFrom(tables []string) string {
if len(tables) == 0 {
return ""
}
s := ""
for _, table := range tables {
table = q.quoteTableNameAndAlias(table)
if s == "" {
s = table
} else {
s += ", " + table
}
}
return "FROM " + s
} | go | func (q *BaseQueryBuilder) BuildFrom(tables []string) string {
if len(tables) == 0 {
return ""
}
s := ""
for _, table := range tables {
table = q.quoteTableNameAndAlias(table)
if s == "" {
s = table
} else {
s += ", " + table
}
}
return "FROM " + s
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildFrom",
"(",
"tables",
"[",
"]",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"tables",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"\"",
"\"",
"\n",
"for",
"_",
... | // BuildFrom generates a FROM clause from the given tables. | [
"BuildFrom",
"generates",
"a",
"FROM",
"clause",
"from",
"the",
"given",
"tables",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L88-L102 |
13,954 | go-ozzo/ozzo-dbx | query_builder.go | BuildJoin | func (q *BaseQueryBuilder) BuildJoin(joins []JoinInfo, params Params) string {
if len(joins) == 0 {
return ""
}
parts := []string{}
for _, join := range joins {
sql := join.Join + " " + q.quoteTableNameAndAlias(join.Table)
on := ""
if join.On != nil {
on = join.On.Build(q.db, params)
}
if on != "" {
sql += " ON " + on
}
parts = append(parts, sql)
}
return strings.Join(parts, " ")
} | go | func (q *BaseQueryBuilder) BuildJoin(joins []JoinInfo, params Params) string {
if len(joins) == 0 {
return ""
}
parts := []string{}
for _, join := range joins {
sql := join.Join + " " + q.quoteTableNameAndAlias(join.Table)
on := ""
if join.On != nil {
on = join.On.Build(q.db, params)
}
if on != "" {
sql += " ON " + on
}
parts = append(parts, sql)
}
return strings.Join(parts, " ")
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildJoin",
"(",
"joins",
"[",
"]",
"JoinInfo",
",",
"params",
"Params",
")",
"string",
"{",
"if",
"len",
"(",
"joins",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"parts",
":=",
"[",... | // BuildJoin generates a JOIN clause from the given join information. | [
"BuildJoin",
"generates",
"a",
"JOIN",
"clause",
"from",
"the",
"given",
"join",
"information",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L105-L122 |
13,955 | go-ozzo/ozzo-dbx | query_builder.go | BuildWhere | func (q *BaseQueryBuilder) BuildWhere(e Expression, params Params) string {
if e != nil {
if c := e.Build(q.db, params); c != "" {
return "WHERE " + c
}
}
return ""
} | go | func (q *BaseQueryBuilder) BuildWhere(e Expression, params Params) string {
if e != nil {
if c := e.Build(q.db, params); c != "" {
return "WHERE " + c
}
}
return ""
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildWhere",
"(",
"e",
"Expression",
",",
"params",
"Params",
")",
"string",
"{",
"if",
"e",
"!=",
"nil",
"{",
"if",
"c",
":=",
"e",
".",
"Build",
"(",
"q",
".",
"db",
",",
"params",
")",
";",
"c",... | // BuildWhere generates a WHERE clause from the given expression. | [
"BuildWhere",
"generates",
"a",
"WHERE",
"clause",
"from",
"the",
"given",
"expression",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L125-L132 |
13,956 | go-ozzo/ozzo-dbx | query_builder.go | BuildGroupBy | func (q *BaseQueryBuilder) BuildGroupBy(cols []string) string {
if len(cols) == 0 {
return ""
}
s := ""
for i, col := range cols {
if i == 0 {
s = q.db.QuoteColumnName(col)
} else {
s += ", " + q.db.QuoteColumnName(col)
}
}
return "GROUP BY " + s
} | go | func (q *BaseQueryBuilder) BuildGroupBy(cols []string) string {
if len(cols) == 0 {
return ""
}
s := ""
for i, col := range cols {
if i == 0 {
s = q.db.QuoteColumnName(col)
} else {
s += ", " + q.db.QuoteColumnName(col)
}
}
return "GROUP BY " + s
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildGroupBy",
"(",
"cols",
"[",
"]",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"cols",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"\"",
"\"",
"\n",
"for",
"i",
... | // BuildGroupBy generates a GROUP BY clause from the given group-by columns. | [
"BuildGroupBy",
"generates",
"a",
"GROUP",
"BY",
"clause",
"from",
"the",
"given",
"group",
"-",
"by",
"columns",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L145-L158 |
13,957 | go-ozzo/ozzo-dbx | query_builder.go | BuildUnion | func (q *BaseQueryBuilder) BuildUnion(unions []UnionInfo, params Params) string {
if len(unions) == 0 {
return ""
}
sql := ""
for i, union := range unions {
if i > 0 {
sql += " "
}
for k, v := range union.Query.params {
params[k] = v
}
u := "UNION"
if union.All {
u = "UNION ALL"
}
sql += fmt.Sprintf("%v (%v)", u, union.Query.sql)
}
return sql
} | go | func (q *BaseQueryBuilder) BuildUnion(unions []UnionInfo, params Params) string {
if len(unions) == 0 {
return ""
}
sql := ""
for i, union := range unions {
if i > 0 {
sql += " "
}
for k, v := range union.Query.params {
params[k] = v
}
u := "UNION"
if union.All {
u = "UNION ALL"
}
sql += fmt.Sprintf("%v (%v)", u, union.Query.sql)
}
return sql
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildUnion",
"(",
"unions",
"[",
"]",
"UnionInfo",
",",
"params",
"Params",
")",
"string",
"{",
"if",
"len",
"(",
"unions",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"sql",
":=",
"\... | // BuildUnion generates a UNION clause from the given union information. | [
"BuildUnion",
"generates",
"a",
"UNION",
"clause",
"from",
"the",
"given",
"union",
"information",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L172-L191 |
13,958 | go-ozzo/ozzo-dbx | query_builder.go | BuildOrderBy | func (q *BaseQueryBuilder) BuildOrderBy(cols []string) string {
if len(cols) == 0 {
return ""
}
s := ""
for i, col := range cols {
if i > 0 {
s += ", "
}
matches := orderRegex.FindStringSubmatch(col)
if len(matches) == 0 {
s += q.db.QuoteColumnName(col)
} else {
col := col[:len(col)-len(matches[0])]
dir := matches[1]
s += q.db.QuoteColumnName(col) + " " + dir
}
}
return "ORDER BY " + s
} | go | func (q *BaseQueryBuilder) BuildOrderBy(cols []string) string {
if len(cols) == 0 {
return ""
}
s := ""
for i, col := range cols {
if i > 0 {
s += ", "
}
matches := orderRegex.FindStringSubmatch(col)
if len(matches) == 0 {
s += q.db.QuoteColumnName(col)
} else {
col := col[:len(col)-len(matches[0])]
dir := matches[1]
s += q.db.QuoteColumnName(col) + " " + dir
}
}
return "ORDER BY " + s
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildOrderBy",
"(",
"cols",
"[",
"]",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"cols",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"\"",
"\"",
"\n",
"for",
"i",
... | // BuildOrderBy generates the ORDER BY clause. | [
"BuildOrderBy",
"generates",
"the",
"ORDER",
"BY",
"clause",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L196-L215 |
13,959 | go-ozzo/ozzo-dbx | query_builder.go | BuildLimit | func (q *BaseQueryBuilder) BuildLimit(limit int64, offset int64) string {
if limit < 0 && offset > 0 {
// most DBMS requires LIMIT when OFFSET is present
limit = 9223372036854775807 // 2^63 - 1
}
sql := ""
if limit >= 0 {
sql = fmt.Sprintf("LIMIT %v", limit)
}
if offset <= 0 {
return sql
}
if sql != "" {
sql += " "
}
return sql + fmt.Sprintf("OFFSET %v", offset)
} | go | func (q *BaseQueryBuilder) BuildLimit(limit int64, offset int64) string {
if limit < 0 && offset > 0 {
// most DBMS requires LIMIT when OFFSET is present
limit = 9223372036854775807 // 2^63 - 1
}
sql := ""
if limit >= 0 {
sql = fmt.Sprintf("LIMIT %v", limit)
}
if offset <= 0 {
return sql
}
if sql != "" {
sql += " "
}
return sql + fmt.Sprintf("OFFSET %v", offset)
} | [
"func",
"(",
"q",
"*",
"BaseQueryBuilder",
")",
"BuildLimit",
"(",
"limit",
"int64",
",",
"offset",
"int64",
")",
"string",
"{",
"if",
"limit",
"<",
"0",
"&&",
"offset",
">",
"0",
"{",
"// most DBMS requires LIMIT when OFFSET is present",
"limit",
"=",
"922337... | // BuildLimit generates the LIMIT clause. | [
"BuildLimit",
"generates",
"the",
"LIMIT",
"clause",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query_builder.go#L218-L235 |
13,960 | go-ozzo/ozzo-dbx | rows.go | ScanMap | func (r *Rows) ScanMap(a NullStringMap) error {
cols, _ := r.Columns()
var refs []interface{}
for i := 0; i < len(cols); i++ {
var t sql.NullString
refs = append(refs, &t)
}
if err := r.Scan(refs...); err != nil {
return err
}
for i, col := range cols {
a[col] = *refs[i].(*sql.NullString)
}
return nil
} | go | func (r *Rows) ScanMap(a NullStringMap) error {
cols, _ := r.Columns()
var refs []interface{}
for i := 0; i < len(cols); i++ {
var t sql.NullString
refs = append(refs, &t)
}
if err := r.Scan(refs...); err != nil {
return err
}
for i, col := range cols {
a[col] = *refs[i].(*sql.NullString)
}
return nil
} | [
"func",
"(",
"r",
"*",
"Rows",
")",
"ScanMap",
"(",
"a",
"NullStringMap",
")",
"error",
"{",
"cols",
",",
"_",
":=",
"r",
".",
"Columns",
"(",
")",
"\n",
"var",
"refs",
"[",
"]",
"interface",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"... | // ScanMap populates the current row of data into a NullStringMap.
// Note that the NullStringMap must not be nil, or it will panic.
// The NullStringMap will be populated using column names as keys and their values as
// the corresponding element values. | [
"ScanMap",
"populates",
"the",
"current",
"row",
"of",
"data",
"into",
"a",
"NullStringMap",
".",
"Note",
"that",
"the",
"NullStringMap",
"must",
"not",
"be",
"nil",
"or",
"it",
"will",
"panic",
".",
"The",
"NullStringMap",
"will",
"be",
"populated",
"using"... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/rows.go#L35-L51 |
13,961 | go-ozzo/ozzo-dbx | rows.go | all | func (r *Rows) all(slice interface{}) error {
defer r.Close()
v := reflect.ValueOf(slice)
if v.Kind() != reflect.Ptr || v.IsNil() {
return VarTypeError("must be a pointer")
}
v = indirect(v)
if v.Kind() != reflect.Slice {
return VarTypeError("must be a slice of struct or NullStringMap")
}
if v.IsNil() {
// create an empty slice
v.Set(reflect.MakeSlice(v.Type(), 0, 0))
}
et := v.Type().Elem()
if et.Kind() == reflect.Map {
for r.Next() {
ev, ok := reflect.MakeMap(et).Interface().(NullStringMap)
if !ok {
return VarTypeError("must be a slice of struct or NullStringMap")
}
if err := r.ScanMap(ev); err != nil {
return err
}
v.Set(reflect.Append(v, reflect.ValueOf(ev)))
}
return r.Close()
}
if et.Kind() != reflect.Struct {
return VarTypeError("must be a slice of struct or NullStringMap")
}
si := getStructInfo(et, r.fieldMapFunc)
cols, _ := r.Columns()
for r.Next() {
ev := reflect.New(et).Elem()
refs := make([]interface{}, len(cols))
for i, col := range cols {
if fi, ok := si.dbNameMap[col]; ok {
refs[i] = fi.getField(ev).Addr().Interface()
} else {
refs[i] = &sql.NullString{}
}
}
if err := r.Scan(refs...); err != nil {
return err
}
v.Set(reflect.Append(v, ev))
}
return r.Close()
} | go | func (r *Rows) all(slice interface{}) error {
defer r.Close()
v := reflect.ValueOf(slice)
if v.Kind() != reflect.Ptr || v.IsNil() {
return VarTypeError("must be a pointer")
}
v = indirect(v)
if v.Kind() != reflect.Slice {
return VarTypeError("must be a slice of struct or NullStringMap")
}
if v.IsNil() {
// create an empty slice
v.Set(reflect.MakeSlice(v.Type(), 0, 0))
}
et := v.Type().Elem()
if et.Kind() == reflect.Map {
for r.Next() {
ev, ok := reflect.MakeMap(et).Interface().(NullStringMap)
if !ok {
return VarTypeError("must be a slice of struct or NullStringMap")
}
if err := r.ScanMap(ev); err != nil {
return err
}
v.Set(reflect.Append(v, reflect.ValueOf(ev)))
}
return r.Close()
}
if et.Kind() != reflect.Struct {
return VarTypeError("must be a slice of struct or NullStringMap")
}
si := getStructInfo(et, r.fieldMapFunc)
cols, _ := r.Columns()
for r.Next() {
ev := reflect.New(et).Elem()
refs := make([]interface{}, len(cols))
for i, col := range cols {
if fi, ok := si.dbNameMap[col]; ok {
refs[i] = fi.getField(ev).Addr().Interface()
} else {
refs[i] = &sql.NullString{}
}
}
if err := r.Scan(refs...); err != nil {
return err
}
v.Set(reflect.Append(v, ev))
}
return r.Close()
} | [
"func",
"(",
"r",
"*",
"Rows",
")",
"all",
"(",
"slice",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"r",
".",
"Close",
"(",
")",
"\n\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"slice",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
... | // all populates all rows of query result into a slice of struct or NullStringMap.
// Note that the slice must be given as a pointer. | [
"all",
"populates",
"all",
"rows",
"of",
"query",
"result",
"into",
"a",
"slice",
"of",
"struct",
"or",
"NullStringMap",
".",
"Note",
"that",
"the",
"slice",
"must",
"be",
"given",
"as",
"a",
"pointer",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/rows.go#L93-L151 |
13,962 | go-ozzo/ozzo-dbx | rows.go | column | func (r *Rows) column(slice interface{}) error {
defer r.Close()
v := reflect.ValueOf(slice)
if v.Kind() != reflect.Ptr || v.IsNil() {
return VarTypeError("must be a pointer to a slice")
}
v = indirect(v)
if v.Kind() != reflect.Slice {
return VarTypeError("must be a pointer to a slice")
}
et := v.Type().Elem()
cols, _ := r.Columns()
for r.Next() {
ev := reflect.New(et)
refs := make([]interface{}, len(cols))
for i := range cols {
if i == 0 {
refs[i] = ev.Interface()
} else {
refs[i] = &sql.NullString{}
}
}
if err := r.Scan(refs...); err != nil {
return err
}
v.Set(reflect.Append(v, ev.Elem()))
}
return r.Close()
} | go | func (r *Rows) column(slice interface{}) error {
defer r.Close()
v := reflect.ValueOf(slice)
if v.Kind() != reflect.Ptr || v.IsNil() {
return VarTypeError("must be a pointer to a slice")
}
v = indirect(v)
if v.Kind() != reflect.Slice {
return VarTypeError("must be a pointer to a slice")
}
et := v.Type().Elem()
cols, _ := r.Columns()
for r.Next() {
ev := reflect.New(et)
refs := make([]interface{}, len(cols))
for i := range cols {
if i == 0 {
refs[i] = ev.Interface()
} else {
refs[i] = &sql.NullString{}
}
}
if err := r.Scan(refs...); err != nil {
return err
}
v.Set(reflect.Append(v, ev.Elem()))
}
return r.Close()
} | [
"func",
"(",
"r",
"*",
"Rows",
")",
"column",
"(",
"slice",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"r",
".",
"Close",
"(",
")",
"\n\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"slice",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",... | // column populates the given slice with the first column of the query result.
// Note that the slice must be given as a pointer. | [
"column",
"populates",
"the",
"given",
"slice",
"with",
"the",
"first",
"column",
"of",
"the",
"query",
"result",
".",
"Note",
"that",
"the",
"slice",
"must",
"be",
"given",
"as",
"a",
"pointer",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/rows.go#L155-L188 |
13,963 | go-ozzo/ozzo-dbx | rows.go | one | func (r *Rows) one(a interface{}) error {
defer r.Close()
if !r.Next() {
if err := r.Err(); err != nil {
return err
}
return sql.ErrNoRows
}
var err error
rt := reflect.TypeOf(a)
if rt.Kind() == reflect.Ptr && rt.Elem().Kind() == reflect.Map {
// pointer to map
v := indirect(reflect.ValueOf(a))
if v.IsNil() {
v.Set(reflect.MakeMap(v.Type()))
}
a = v.Interface()
rt = reflect.TypeOf(a)
}
if rt.Kind() == reflect.Map {
v, ok := a.(NullStringMap)
if !ok {
return VarTypeError("must be a NullStringMap")
}
if v == nil {
return VarTypeError("NullStringMap is nil")
}
err = r.ScanMap(v)
} else {
err = r.ScanStruct(a)
}
if err != nil {
return err
}
return r.Close()
} | go | func (r *Rows) one(a interface{}) error {
defer r.Close()
if !r.Next() {
if err := r.Err(); err != nil {
return err
}
return sql.ErrNoRows
}
var err error
rt := reflect.TypeOf(a)
if rt.Kind() == reflect.Ptr && rt.Elem().Kind() == reflect.Map {
// pointer to map
v := indirect(reflect.ValueOf(a))
if v.IsNil() {
v.Set(reflect.MakeMap(v.Type()))
}
a = v.Interface()
rt = reflect.TypeOf(a)
}
if rt.Kind() == reflect.Map {
v, ok := a.(NullStringMap)
if !ok {
return VarTypeError("must be a NullStringMap")
}
if v == nil {
return VarTypeError("NullStringMap is nil")
}
err = r.ScanMap(v)
} else {
err = r.ScanStruct(a)
}
if err != nil {
return err
}
return r.Close()
} | [
"func",
"(",
"r",
"*",
"Rows",
")",
"one",
"(",
"a",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"r",
".",
"Close",
"(",
")",
"\n\n",
"if",
"!",
"r",
".",
"Next",
"(",
")",
"{",
"if",
"err",
":=",
"r",
".",
"Err",
"(",
")",
";",
"e... | // one populates a single row of query result into a struct or a NullStringMap.
// Note that if a struct is given, it should be a pointer. | [
"one",
"populates",
"a",
"single",
"row",
"of",
"query",
"result",
"into",
"a",
"struct",
"or",
"a",
"NullStringMap",
".",
"Note",
"that",
"if",
"a",
"struct",
"is",
"given",
"it",
"should",
"be",
"a",
"pointer",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/rows.go#L192-L233 |
13,964 | go-ozzo/ozzo-dbx | rows.go | row | func (r *Rows) row(a ...interface{}) error {
defer r.Close()
for _, dp := range a {
if _, ok := dp.(*sql.RawBytes); ok {
return VarTypeError("RawBytes isn't allowed on Row()")
}
}
if !r.Next() {
if err := r.Err(); err != nil {
return err
}
return sql.ErrNoRows
}
if err := r.Scan(a...); err != nil {
return err
}
return r.Close()
} | go | func (r *Rows) row(a ...interface{}) error {
defer r.Close()
for _, dp := range a {
if _, ok := dp.(*sql.RawBytes); ok {
return VarTypeError("RawBytes isn't allowed on Row()")
}
}
if !r.Next() {
if err := r.Err(); err != nil {
return err
}
return sql.ErrNoRows
}
if err := r.Scan(a...); err != nil {
return err
}
return r.Close()
} | [
"func",
"(",
"r",
"*",
"Rows",
")",
"row",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"r",
".",
"Close",
"(",
")",
"\n\n",
"for",
"_",
",",
"dp",
":=",
"range",
"a",
"{",
"if",
"_",
",",
"ok",
":=",
"dp",
".",
"(",
... | // row populates a single row of query result into a list of variables. | [
"row",
"populates",
"a",
"single",
"row",
"of",
"query",
"result",
"into",
"a",
"list",
"of",
"variables",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/rows.go#L236-L256 |
13,965 | go-ozzo/ozzo-dbx | query.go | NewQuery | func NewQuery(db *DB, executor Executor, sql string) *Query {
rawSQL, placeholders := db.processSQL(sql)
return &Query{
executor: executor,
sql: sql,
rawSQL: rawSQL,
placeholders: placeholders,
params: Params{},
FieldMapper: db.FieldMapper,
LogFunc: db.LogFunc,
PerfFunc: db.PerfFunc,
}
} | go | func NewQuery(db *DB, executor Executor, sql string) *Query {
rawSQL, placeholders := db.processSQL(sql)
return &Query{
executor: executor,
sql: sql,
rawSQL: rawSQL,
placeholders: placeholders,
params: Params{},
FieldMapper: db.FieldMapper,
LogFunc: db.LogFunc,
PerfFunc: db.PerfFunc,
}
} | [
"func",
"NewQuery",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
",",
"sql",
"string",
")",
"*",
"Query",
"{",
"rawSQL",
",",
"placeholders",
":=",
"db",
".",
"processSQL",
"(",
"sql",
")",
"\n",
"return",
"&",
"Query",
"{",
"executor",
":",
"e... | // NewQuery creates a new Query with the given SQL statement. | [
"NewQuery",
"creates",
"a",
"new",
"Query",
"with",
"the",
"given",
"SQL",
"statement",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L58-L70 |
13,966 | go-ozzo/ozzo-dbx | query.go | logSQL | func (q *Query) logSQL() string {
s := q.sql
for k, v := range q.params {
if valuer, ok := v.(driver.Valuer); ok && valuer != nil {
v, _ = valuer.Value()
}
var sv string
if str, ok := v.(string); ok {
sv = "'" + strings.Replace(str, "'", "''", -1) + "'"
} else if bs, ok := v.([]byte); ok {
sv = "'" + strings.Replace(string(bs), "'", "''", -1) + "'"
} else {
sv = fmt.Sprintf("%v", v)
}
s = strings.Replace(s, "{:"+k+"}", sv, -1)
}
return s
} | go | func (q *Query) logSQL() string {
s := q.sql
for k, v := range q.params {
if valuer, ok := v.(driver.Valuer); ok && valuer != nil {
v, _ = valuer.Value()
}
var sv string
if str, ok := v.(string); ok {
sv = "'" + strings.Replace(str, "'", "''", -1) + "'"
} else if bs, ok := v.([]byte); ok {
sv = "'" + strings.Replace(string(bs), "'", "''", -1) + "'"
} else {
sv = fmt.Sprintf("%v", v)
}
s = strings.Replace(s, "{:"+k+"}", sv, -1)
}
return s
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"logSQL",
"(",
")",
"string",
"{",
"s",
":=",
"q",
".",
"sql",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"q",
".",
"params",
"{",
"if",
"valuer",
",",
"ok",
":=",
"v",
".",
"(",
"driver",
".",
"Valuer",
... | // logSQL returns the SQL statement with parameters being replaced with the actual values.
// The result is only for logging purpose and should not be used to execute. | [
"logSQL",
"returns",
"the",
"SQL",
"statement",
"with",
"parameters",
"being",
"replaced",
"with",
"the",
"actual",
"values",
".",
"The",
"result",
"is",
"only",
"for",
"logging",
"purpose",
"and",
"should",
"not",
"be",
"used",
"to",
"execute",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L92-L109 |
13,967 | go-ozzo/ozzo-dbx | query.go | log | func (q *Query) log(start time.Time, execute bool) {
if q.LogFunc == nil && q.PerfFunc == nil {
return
}
ns := time.Now().Sub(start).Nanoseconds()
s := q.logSQL()
if q.LogFunc != nil {
if execute {
q.LogFunc("[%.2fms] Execute SQL: %v", float64(ns)/1e6, s)
} else {
q.LogFunc("[%.2fms] Query SQL: %v", float64(ns)/1e6, s)
}
}
if q.PerfFunc != nil {
q.PerfFunc(ns, s, execute)
}
} | go | func (q *Query) log(start time.Time, execute bool) {
if q.LogFunc == nil && q.PerfFunc == nil {
return
}
ns := time.Now().Sub(start).Nanoseconds()
s := q.logSQL()
if q.LogFunc != nil {
if execute {
q.LogFunc("[%.2fms] Execute SQL: %v", float64(ns)/1e6, s)
} else {
q.LogFunc("[%.2fms] Query SQL: %v", float64(ns)/1e6, s)
}
}
if q.PerfFunc != nil {
q.PerfFunc(ns, s, execute)
}
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"log",
"(",
"start",
"time",
".",
"Time",
",",
"execute",
"bool",
")",
"{",
"if",
"q",
".",
"LogFunc",
"==",
"nil",
"&&",
"q",
".",
"PerfFunc",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"ns",
":=",
"time"... | // log logs a message for the currently executed SQL statement. | [
"log",
"logs",
"a",
"message",
"for",
"the",
"currently",
"executed",
"SQL",
"statement",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L112-L128 |
13,968 | go-ozzo/ozzo-dbx | query.go | Close | func (q *Query) Close() error {
if q.stmt == nil {
return nil
}
err := q.stmt.Close()
q.stmt = nil
return err
} | go | func (q *Query) Close() error {
if q.stmt == nil {
return nil
}
err := q.stmt.Close()
q.stmt = nil
return err
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"q",
".",
"stmt",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"err",
":=",
"q",
".",
"stmt",
".",
"Close",
"(",
")",
"\n",
"q",
".",
"stmt",
"=",
"nil",
"... | // Close closes the underlying prepared statement.
// Close does nothing if the query has not been prepared before. | [
"Close",
"closes",
"the",
"underlying",
"prepared",
"statement",
".",
"Close",
"does",
"nothing",
"if",
"the",
"query",
"has",
"not",
"been",
"prepared",
"before",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L149-L157 |
13,969 | go-ozzo/ozzo-dbx | query.go | Execute | func (q *Query) Execute() (result sql.Result, err error) {
err = q.LastError
q.LastError = nil
if err != nil {
return
}
var params []interface{}
params, err = replacePlaceholders(q.placeholders, q.params)
if err != nil {
return
}
defer q.log(time.Now(), true)
if q.ctx == nil {
if q.stmt == nil {
result, err = q.executor.Exec(q.rawSQL, params...)
} else {
result, err = q.stmt.Exec(params...)
}
} else {
if q.stmt == nil {
result, err = q.executor.ExecContext(q.ctx, q.rawSQL, params...)
} else {
result, err = q.stmt.ExecContext(q.ctx, params...)
}
}
return
} | go | func (q *Query) Execute() (result sql.Result, err error) {
err = q.LastError
q.LastError = nil
if err != nil {
return
}
var params []interface{}
params, err = replacePlaceholders(q.placeholders, q.params)
if err != nil {
return
}
defer q.log(time.Now(), true)
if q.ctx == nil {
if q.stmt == nil {
result, err = q.executor.Exec(q.rawSQL, params...)
} else {
result, err = q.stmt.Exec(params...)
}
} else {
if q.stmt == nil {
result, err = q.executor.ExecContext(q.ctx, q.rawSQL, params...)
} else {
result, err = q.stmt.ExecContext(q.ctx, params...)
}
}
return
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Execute",
"(",
")",
"(",
"result",
"sql",
".",
"Result",
",",
"err",
"error",
")",
"{",
"err",
"=",
"q",
".",
"LastError",
"\n",
"q",
".",
"LastError",
"=",
"nil",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // Execute executes the SQL statement without retrieving data. | [
"Execute",
"executes",
"the",
"SQL",
"statement",
"without",
"retrieving",
"data",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L173-L202 |
13,970 | go-ozzo/ozzo-dbx | query.go | Row | func (q *Query) Row(a ...interface{}) error {
rows, err := q.Rows()
if err != nil {
return err
}
return rows.row(a...)
} | go | func (q *Query) Row(a ...interface{}) error {
rows, err := q.Rows()
if err != nil {
return err
}
return rows.row(a...)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Row",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"rows",
",",
"err",
":=",
"q",
".",
"Rows",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"row... | // Row executes the SQL statement and populates the first row of the result into a list of variables.
// Note that the number of the variables should match to that of the columns in the query result.
// Note that when the query has no rows in the result set, an sql.ErrNoRows will be returned. | [
"Row",
"executes",
"the",
"SQL",
"statement",
"and",
"populates",
"the",
"first",
"row",
"of",
"the",
"result",
"into",
"a",
"list",
"of",
"variables",
".",
"Note",
"that",
"the",
"number",
"of",
"the",
"variables",
"should",
"match",
"to",
"that",
"of",
... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L231-L237 |
13,971 | go-ozzo/ozzo-dbx | query.go | Column | func (q *Query) Column(a interface{}) error {
rows, err := q.Rows()
if err != nil {
return err
}
return rows.column(a)
} | go | func (q *Query) Column(a interface{}) error {
rows, err := q.Rows()
if err != nil {
return err
}
return rows.column(a)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Column",
"(",
"a",
"interface",
"{",
"}",
")",
"error",
"{",
"rows",
",",
"err",
":=",
"q",
".",
"Rows",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"rows",
... | // Column executes the SQL statement and populates the first column of the result into a slice.
// Note that the parameter must be a pointer to a slice. | [
"Column",
"executes",
"the",
"SQL",
"statement",
"and",
"populates",
"the",
"first",
"column",
"of",
"the",
"result",
"into",
"a",
"slice",
".",
"Note",
"that",
"the",
"parameter",
"must",
"be",
"a",
"pointer",
"to",
"a",
"slice",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L241-L247 |
13,972 | go-ozzo/ozzo-dbx | query.go | Rows | func (q *Query) Rows() (rows *Rows, err error) {
err = q.LastError
q.LastError = nil
if err != nil {
return
}
var params []interface{}
params, err = replacePlaceholders(q.placeholders, q.params)
if err != nil {
return
}
defer q.log(time.Now(), false)
var rr *sql.Rows
if q.ctx == nil {
if q.stmt == nil {
rr, err = q.executor.Query(q.rawSQL, params...)
} else {
rr, err = q.stmt.Query(params...)
}
} else {
if q.stmt == nil {
rr, err = q.executor.QueryContext(q.ctx, q.rawSQL, params...)
} else {
rr, err = q.stmt.QueryContext(q.ctx, params...)
}
}
rows = &Rows{rr, q.FieldMapper}
return
} | go | func (q *Query) Rows() (rows *Rows, err error) {
err = q.LastError
q.LastError = nil
if err != nil {
return
}
var params []interface{}
params, err = replacePlaceholders(q.placeholders, q.params)
if err != nil {
return
}
defer q.log(time.Now(), false)
var rr *sql.Rows
if q.ctx == nil {
if q.stmt == nil {
rr, err = q.executor.Query(q.rawSQL, params...)
} else {
rr, err = q.stmt.Query(params...)
}
} else {
if q.stmt == nil {
rr, err = q.executor.QueryContext(q.ctx, q.rawSQL, params...)
} else {
rr, err = q.stmt.QueryContext(q.ctx, params...)
}
}
rows = &Rows{rr, q.FieldMapper}
return
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Rows",
"(",
")",
"(",
"rows",
"*",
"Rows",
",",
"err",
"error",
")",
"{",
"err",
"=",
"q",
".",
"LastError",
"\n",
"q",
".",
"LastError",
"=",
"nil",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"... | // Rows executes the SQL statement and returns a Rows object to allow retrieving data row by row. | [
"Rows",
"executes",
"the",
"SQL",
"statement",
"and",
"returns",
"a",
"Rows",
"object",
"to",
"allow",
"retrieving",
"data",
"row",
"by",
"row",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L250-L281 |
13,973 | go-ozzo/ozzo-dbx | query.go | replacePlaceholders | func replacePlaceholders(placeholders []string, params Params) ([]interface{}, error) {
if len(placeholders) == 0 {
return nil, nil
}
var result []interface{}
for _, name := range placeholders {
if value, ok := params[name]; ok {
result = append(result, value)
} else {
return nil, errors.New("Named parameter not found: " + name)
}
}
return result, nil
} | go | func replacePlaceholders(placeholders []string, params Params) ([]interface{}, error) {
if len(placeholders) == 0 {
return nil, nil
}
var result []interface{}
for _, name := range placeholders {
if value, ok := params[name]; ok {
result = append(result, value)
} else {
return nil, errors.New("Named parameter not found: " + name)
}
}
return result, nil
} | [
"func",
"replacePlaceholders",
"(",
"placeholders",
"[",
"]",
"string",
",",
"params",
"Params",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"len",
"(",
"placeholders",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\... | // replacePlaceholders converts a list of named parameters into a list of anonymous parameters. | [
"replacePlaceholders",
"converts",
"a",
"list",
"of",
"named",
"parameters",
"into",
"a",
"list",
"of",
"anonymous",
"parameters",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/query.go#L284-L298 |
13,974 | go-ozzo/ozzo-dbx | builder_oci.go | NewOciBuilder | func NewOciBuilder(db *DB, executor Executor) Builder {
return &OciBuilder{
NewBaseBuilder(db, executor),
&OciQueryBuilder{NewBaseQueryBuilder(db)},
}
} | go | func NewOciBuilder(db *DB, executor Executor) Builder {
return &OciBuilder{
NewBaseBuilder(db, executor),
&OciQueryBuilder{NewBaseQueryBuilder(db)},
}
} | [
"func",
"NewOciBuilder",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
")",
"Builder",
"{",
"return",
"&",
"OciBuilder",
"{",
"NewBaseBuilder",
"(",
"db",
",",
"executor",
")",
",",
"&",
"OciQueryBuilder",
"{",
"NewBaseQueryBuilder",
"(",
"db",
")",
"... | // NewOciBuilder creates a new OciBuilder instance. | [
"NewOciBuilder",
"creates",
"a",
"new",
"OciBuilder",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_oci.go#L25-L30 |
13,975 | go-ozzo/ozzo-dbx | builder.go | NewQuery | func (b *BaseBuilder) NewQuery(sql string) *Query {
return NewQuery(b.db, b.executor, sql)
} | go | func (b *BaseBuilder) NewQuery(sql string) *Query {
return NewQuery(b.db, b.executor, sql)
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"NewQuery",
"(",
"sql",
"string",
")",
"*",
"Query",
"{",
"return",
"NewQuery",
"(",
"b",
".",
"db",
",",
"b",
".",
"executor",
",",
"sql",
")",
"\n",
"}"
] | // NewQuery creates a new Query object with the given SQL statement.
// The SQL statement may contain parameter placeholders which can be bound with actual parameter
// values before the statement is executed. | [
"NewQuery",
"creates",
"a",
"new",
"Query",
"object",
"with",
"the",
"given",
"SQL",
"statement",
".",
"The",
"SQL",
"statement",
"may",
"contain",
"parameter",
"placeholders",
"which",
"can",
"be",
"bound",
"with",
"actual",
"parameter",
"values",
"before",
"... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L131-L133 |
13,976 | go-ozzo/ozzo-dbx | builder.go | Insert | func (b *BaseBuilder) Insert(table string, cols Params) *Query {
names := make([]string, 0, len(cols))
for name := range cols {
names = append(names, name)
}
sort.Strings(names)
params := Params{}
columns := make([]string, 0, len(names))
values := make([]string, 0, len(names))
for _, name := range names {
columns = append(columns, b.db.QuoteColumnName(name))
value := cols[name]
if e, ok := value.(Expression); ok {
values = append(values, e.Build(b.db, params))
} else {
values = append(values, fmt.Sprintf("{:p%v}", len(params)))
params[fmt.Sprintf("p%v", len(params))] = value
}
}
var sql string
if len(names) == 0 {
sql = fmt.Sprintf("INSERT INTO %v DEFAULT VALUES", b.db.QuoteTableName(table))
} else {
sql = fmt.Sprintf("INSERT INTO %v (%v) VALUES (%v)",
b.db.QuoteTableName(table),
strings.Join(columns, ", "),
strings.Join(values, ", "),
)
}
return b.NewQuery(sql).Bind(params)
} | go | func (b *BaseBuilder) Insert(table string, cols Params) *Query {
names := make([]string, 0, len(cols))
for name := range cols {
names = append(names, name)
}
sort.Strings(names)
params := Params{}
columns := make([]string, 0, len(names))
values := make([]string, 0, len(names))
for _, name := range names {
columns = append(columns, b.db.QuoteColumnName(name))
value := cols[name]
if e, ok := value.(Expression); ok {
values = append(values, e.Build(b.db, params))
} else {
values = append(values, fmt.Sprintf("{:p%v}", len(params)))
params[fmt.Sprintf("p%v", len(params))] = value
}
}
var sql string
if len(names) == 0 {
sql = fmt.Sprintf("INSERT INTO %v DEFAULT VALUES", b.db.QuoteTableName(table))
} else {
sql = fmt.Sprintf("INSERT INTO %v (%v) VALUES (%v)",
b.db.QuoteTableName(table),
strings.Join(columns, ", "),
strings.Join(values, ", "),
)
}
return b.NewQuery(sql).Bind(params)
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"Insert",
"(",
"table",
"string",
",",
"cols",
"Params",
")",
"*",
"Query",
"{",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"cols",
")",
")",
"\n",
"for",
"name",
":=",
... | // Insert creates a Query that represents an INSERT SQL statement.
// The keys of cols are the column names, while the values of cols are the corresponding column
// values to be inserted. | [
"Insert",
"creates",
"a",
"Query",
"that",
"represents",
"an",
"INSERT",
"SQL",
"statement",
".",
"The",
"keys",
"of",
"cols",
"are",
"the",
"column",
"names",
"while",
"the",
"values",
"of",
"cols",
"are",
"the",
"corresponding",
"column",
"values",
"to",
... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L166-L199 |
13,977 | go-ozzo/ozzo-dbx | builder.go | CreateTable | func (b *BaseBuilder) CreateTable(table string, cols map[string]string, options ...string) *Query {
names := []string{}
for name := range cols {
names = append(names, name)
}
sort.Strings(names)
columns := []string{}
for _, name := range names {
columns = append(columns, b.db.QuoteColumnName(name)+" "+cols[name])
}
sql := fmt.Sprintf("CREATE TABLE %v (%v)", b.db.QuoteTableName(table), strings.Join(columns, ", "))
for _, opt := range options {
sql += " " + opt
}
return b.NewQuery(sql)
} | go | func (b *BaseBuilder) CreateTable(table string, cols map[string]string, options ...string) *Query {
names := []string{}
for name := range cols {
names = append(names, name)
}
sort.Strings(names)
columns := []string{}
for _, name := range names {
columns = append(columns, b.db.QuoteColumnName(name)+" "+cols[name])
}
sql := fmt.Sprintf("CREATE TABLE %v (%v)", b.db.QuoteTableName(table), strings.Join(columns, ", "))
for _, opt := range options {
sql += " " + opt
}
return b.NewQuery(sql)
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"CreateTable",
"(",
"table",
"string",
",",
"cols",
"map",
"[",
"string",
"]",
"string",
",",
"options",
"...",
"string",
")",
"*",
"Query",
"{",
"names",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"... | // CreateTable creates a Query that represents a CREATE TABLE SQL statement.
// The keys of cols are the column names, while the values of cols are the corresponding column types.
// The optional "options" parameters will be appended to the generated SQL statement. | [
"CreateTable",
"creates",
"a",
"Query",
"that",
"represents",
"a",
"CREATE",
"TABLE",
"SQL",
"statement",
".",
"The",
"keys",
"of",
"cols",
"are",
"the",
"column",
"names",
"while",
"the",
"values",
"of",
"cols",
"are",
"the",
"corresponding",
"column",
"typ... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L265-L283 |
13,978 | go-ozzo/ozzo-dbx | builder.go | TruncateTable | func (b *BaseBuilder) TruncateTable(table string) *Query {
sql := "TRUNCATE TABLE " + b.db.QuoteTableName(table)
return b.NewQuery(sql)
} | go | func (b *BaseBuilder) TruncateTable(table string) *Query {
sql := "TRUNCATE TABLE " + b.db.QuoteTableName(table)
return b.NewQuery(sql)
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"TruncateTable",
"(",
"table",
"string",
")",
"*",
"Query",
"{",
"sql",
":=",
"\"",
"\"",
"+",
"b",
".",
"db",
".",
"QuoteTableName",
"(",
"table",
")",
"\n",
"return",
"b",
".",
"NewQuery",
"(",
"sql",
")... | // TruncateTable creates a Query that can be used to truncate a table. | [
"TruncateTable",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"truncate",
"a",
"table",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L298-L301 |
13,979 | go-ozzo/ozzo-dbx | builder.go | AddColumn | func (b *BaseBuilder) AddColumn(table, col, typ string) *Query {
sql := fmt.Sprintf("ALTER TABLE %v ADD %v %v", b.db.QuoteTableName(table), b.db.QuoteColumnName(col), typ)
return b.NewQuery(sql)
} | go | func (b *BaseBuilder) AddColumn(table, col, typ string) *Query {
sql := fmt.Sprintf("ALTER TABLE %v ADD %v %v", b.db.QuoteTableName(table), b.db.QuoteColumnName(col), typ)
return b.NewQuery(sql)
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"AddColumn",
"(",
"table",
",",
"col",
",",
"typ",
"string",
")",
"*",
"Query",
"{",
"sql",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"db",
".",
"QuoteTableName",
"(",
"table",
")",
",... | // AddColumn creates a Query that can be used to add a column to a table. | [
"AddColumn",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"add",
"a",
"column",
"to",
"a",
"table",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L304-L307 |
13,980 | go-ozzo/ozzo-dbx | builder.go | CreateIndex | func (b *BaseBuilder) CreateIndex(table, name string, cols ...string) *Query {
sql := fmt.Sprintf("CREATE INDEX %v ON %v (%v)",
b.db.QuoteColumnName(name),
b.db.QuoteTableName(table),
b.quoteColumns(cols))
return b.NewQuery(sql)
} | go | func (b *BaseBuilder) CreateIndex(table, name string, cols ...string) *Query {
sql := fmt.Sprintf("CREATE INDEX %v ON %v (%v)",
b.db.QuoteColumnName(name),
b.db.QuoteTableName(table),
b.quoteColumns(cols))
return b.NewQuery(sql)
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"CreateIndex",
"(",
"table",
",",
"name",
"string",
",",
"cols",
"...",
"string",
")",
"*",
"Query",
"{",
"sql",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"db",
".",
"QuoteColumnName",
"... | // CreateIndex creates a Query that can be used to create an index for a table. | [
"CreateIndex",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"create",
"an",
"index",
"for",
"a",
"table",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L368-L374 |
13,981 | go-ozzo/ozzo-dbx | builder.go | quoteColumns | func (b *BaseBuilder) quoteColumns(cols []string) string {
s := ""
for i, col := range cols {
if i == 0 {
s = b.db.QuoteColumnName(col)
} else {
s += ", " + b.db.QuoteColumnName(col)
}
}
return s
} | go | func (b *BaseBuilder) quoteColumns(cols []string) string {
s := ""
for i, col := range cols {
if i == 0 {
s = b.db.QuoteColumnName(col)
} else {
s += ", " + b.db.QuoteColumnName(col)
}
}
return s
} | [
"func",
"(",
"b",
"*",
"BaseBuilder",
")",
"quoteColumns",
"(",
"cols",
"[",
"]",
"string",
")",
"string",
"{",
"s",
":=",
"\"",
"\"",
"\n",
"for",
"i",
",",
"col",
":=",
"range",
"cols",
"{",
"if",
"i",
"==",
"0",
"{",
"s",
"=",
"b",
".",
"d... | // quoteColumns quotes a list of columns and concatenates them with commas. | [
"quoteColumns",
"quotes",
"a",
"list",
"of",
"columns",
"and",
"concatenates",
"them",
"with",
"commas",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder.go#L392-L402 |
13,982 | go-ozzo/ozzo-dbx | builder_mssql.go | NewMssqlBuilder | func NewMssqlBuilder(db *DB, executor Executor) Builder {
return &MssqlBuilder{
NewBaseBuilder(db, executor),
&MssqlQueryBuilder{NewBaseQueryBuilder(db)},
}
} | go | func NewMssqlBuilder(db *DB, executor Executor) Builder {
return &MssqlBuilder{
NewBaseBuilder(db, executor),
&MssqlQueryBuilder{NewBaseQueryBuilder(db)},
}
} | [
"func",
"NewMssqlBuilder",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
")",
"Builder",
"{",
"return",
"&",
"MssqlBuilder",
"{",
"NewBaseBuilder",
"(",
"db",
",",
"executor",
")",
",",
"&",
"MssqlQueryBuilder",
"{",
"NewBaseQueryBuilder",
"(",
"db",
")... | // NewMssqlBuilder creates a new MssqlBuilder instance. | [
"NewMssqlBuilder",
"creates",
"a",
"new",
"MssqlBuilder",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_mssql.go#L26-L31 |
13,983 | go-ozzo/ozzo-dbx | builder_mysql.go | NewMysqlBuilder | func NewMysqlBuilder(db *DB, executor Executor) Builder {
return &MysqlBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | go | func NewMysqlBuilder(db *DB, executor Executor) Builder {
return &MysqlBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | [
"func",
"NewMysqlBuilder",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
")",
"Builder",
"{",
"return",
"&",
"MysqlBuilder",
"{",
"NewBaseBuilder",
"(",
"db",
",",
"executor",
")",
",",
"NewBaseQueryBuilder",
"(",
"db",
")",
",",
"}",
"\n",
"}"
] | // NewMysqlBuilder creates a new MysqlBuilder instance. | [
"NewMysqlBuilder",
"creates",
"a",
"new",
"MysqlBuilder",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_mysql.go#L23-L28 |
13,984 | go-ozzo/ozzo-dbx | builder_mysql.go | DropForeignKey | func (b *MysqlBuilder) DropForeignKey(table, name string) *Query {
sql := fmt.Sprintf("ALTER TABLE %v DROP FOREIGN KEY %v", b.db.QuoteTableName(table), b.db.QuoteColumnName(name))
return b.db.NewQuery(sql)
} | go | func (b *MysqlBuilder) DropForeignKey(table, name string) *Query {
sql := fmt.Sprintf("ALTER TABLE %v DROP FOREIGN KEY %v", b.db.QuoteTableName(table), b.db.QuoteColumnName(name))
return b.db.NewQuery(sql)
} | [
"func",
"(",
"b",
"*",
"MysqlBuilder",
")",
"DropForeignKey",
"(",
"table",
",",
"name",
"string",
")",
"*",
"Query",
"{",
"sql",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"db",
".",
"QuoteTableName",
"(",
"table",
")",
",",
"b",... | // DropForeignKey creates a Query that can be used to remove the named foreign key constraint from a table. | [
"DropForeignKey",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"remove",
"the",
"named",
"foreign",
"key",
"constraint",
"from",
"a",
"table",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_mysql.go#L130-L133 |
13,985 | go-ozzo/ozzo-dbx | db.go | NewFromDB | func NewFromDB(sqlDB *sql.DB, driverName string) *DB {
db := &DB{
driverName: driverName,
sqlDB: sqlDB,
FieldMapper: DefaultFieldMapFunc,
}
db.Builder = db.newBuilder(db.sqlDB)
return db
} | go | func NewFromDB(sqlDB *sql.DB, driverName string) *DB {
db := &DB{
driverName: driverName,
sqlDB: sqlDB,
FieldMapper: DefaultFieldMapFunc,
}
db.Builder = db.newBuilder(db.sqlDB)
return db
} | [
"func",
"NewFromDB",
"(",
"sqlDB",
"*",
"sql",
".",
"DB",
",",
"driverName",
"string",
")",
"*",
"DB",
"{",
"db",
":=",
"&",
"DB",
"{",
"driverName",
":",
"driverName",
",",
"sqlDB",
":",
"sqlDB",
",",
"FieldMapper",
":",
"DefaultFieldMapFunc",
",",
"}... | // NewFromDB encapsulates an existing database connection. | [
"NewFromDB",
"encapsulates",
"an",
"existing",
"database",
"connection",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L66-L74 |
13,986 | go-ozzo/ozzo-dbx | db.go | Clone | func (db *DB) Clone() *DB {
db2 := &DB{
driverName: db.driverName,
sqlDB: db.sqlDB,
FieldMapper: db.FieldMapper,
PerfFunc: db.PerfFunc,
LogFunc: db.LogFunc,
}
db2.Builder = db2.newBuilder(db.sqlDB)
return db2
} | go | func (db *DB) Clone() *DB {
db2 := &DB{
driverName: db.driverName,
sqlDB: db.sqlDB,
FieldMapper: db.FieldMapper,
PerfFunc: db.PerfFunc,
LogFunc: db.LogFunc,
}
db2.Builder = db2.newBuilder(db.sqlDB)
return db2
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Clone",
"(",
")",
"*",
"DB",
"{",
"db2",
":=",
"&",
"DB",
"{",
"driverName",
":",
"db",
".",
"driverName",
",",
"sqlDB",
":",
"db",
".",
"sqlDB",
",",
"FieldMapper",
":",
"db",
".",
"FieldMapper",
",",
"PerfFun... | // Clone makes a shallow copy of DB. | [
"Clone",
"makes",
"a",
"shallow",
"copy",
"of",
"DB",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L102-L112 |
13,987 | go-ozzo/ozzo-dbx | db.go | BeginTx | func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
tx, err := db.sqlDB.BeginTx(ctx, opts)
if err != nil {
return nil, err
}
return &Tx{db.newBuilder(tx), tx}, nil
} | go | func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
tx, err := db.sqlDB.BeginTx(ctx, opts)
if err != nil {
return nil, err
}
return &Tx{db.newBuilder(tx), tx}, nil
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"BeginTx",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"sql",
".",
"TxOptions",
")",
"(",
"*",
"Tx",
",",
"error",
")",
"{",
"tx",
",",
"err",
":=",
"db",
".",
"sqlDB",
".",
"BeginTx",
"(",
"ctx",... | // BeginTx starts a transaction with the given context and transaction options. | [
"BeginTx",
"starts",
"a",
"transaction",
"with",
"the",
"given",
"context",
"and",
"transaction",
"options",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L136-L142 |
13,988 | go-ozzo/ozzo-dbx | db.go | Wrap | func (db *DB) Wrap(sqlTx *sql.Tx) *Tx {
return &Tx{db.newBuilder(sqlTx), sqlTx}
} | go | func (db *DB) Wrap(sqlTx *sql.Tx) *Tx {
return &Tx{db.newBuilder(sqlTx), sqlTx}
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Wrap",
"(",
"sqlTx",
"*",
"sql",
".",
"Tx",
")",
"*",
"Tx",
"{",
"return",
"&",
"Tx",
"{",
"db",
".",
"newBuilder",
"(",
"sqlTx",
")",
",",
"sqlTx",
"}",
"\n",
"}"
] | // Wrap encapsulates an existing transaction. | [
"Wrap",
"encapsulates",
"an",
"existing",
"transaction",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L145-L147 |
13,989 | go-ozzo/ozzo-dbx | db.go | Transactional | func (db *DB) Transactional(f func(*Tx) error) (err error) {
tx, err := db.Begin()
if err != nil {
return err
}
defer func() {
if p := recover(); p != nil {
tx.Rollback()
panic(p)
} else if err != nil {
if err2 := tx.Rollback(); err2 != nil {
if err2 == sql.ErrTxDone {
return
}
err = Errors{err, err2}
}
} else {
if err = tx.Commit(); err == sql.ErrTxDone {
err = nil
}
}
}()
err = f(tx)
return err
} | go | func (db *DB) Transactional(f func(*Tx) error) (err error) {
tx, err := db.Begin()
if err != nil {
return err
}
defer func() {
if p := recover(); p != nil {
tx.Rollback()
panic(p)
} else if err != nil {
if err2 := tx.Rollback(); err2 != nil {
if err2 == sql.ErrTxDone {
return
}
err = Errors{err, err2}
}
} else {
if err = tx.Commit(); err == sql.ErrTxDone {
err = nil
}
}
}()
err = f(tx)
return err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Transactional",
"(",
"f",
"func",
"(",
"*",
"Tx",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"tx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err"... | // Transactional starts a transaction and executes the given function.
// If the function returns an error, the transaction will be rolled back.
// Otherwise, the transaction will be committed. | [
"Transactional",
"starts",
"a",
"transaction",
"and",
"executes",
"the",
"given",
"function",
".",
"If",
"the",
"function",
"returns",
"an",
"error",
"the",
"transaction",
"will",
"be",
"rolled",
"back",
".",
"Otherwise",
"the",
"transaction",
"will",
"be",
"c... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L152-L179 |
13,990 | go-ozzo/ozzo-dbx | db.go | TransactionalContext | func (db *DB) TransactionalContext(ctx context.Context, opts *sql.TxOptions, f func(*Tx) error) (err error) {
tx, err := db.BeginTx(ctx, opts)
if err != nil {
return err
}
defer func() {
if p := recover(); p != nil {
tx.Rollback()
panic(p)
} else if err != nil {
if err2 := tx.Rollback(); err2 != nil {
if err2 == sql.ErrTxDone {
return
}
err = Errors{err, err2}
}
} else {
if err = tx.Commit(); err == sql.ErrTxDone {
err = nil
}
}
}()
err = f(tx)
return err
} | go | func (db *DB) TransactionalContext(ctx context.Context, opts *sql.TxOptions, f func(*Tx) error) (err error) {
tx, err := db.BeginTx(ctx, opts)
if err != nil {
return err
}
defer func() {
if p := recover(); p != nil {
tx.Rollback()
panic(p)
} else if err != nil {
if err2 := tx.Rollback(); err2 != nil {
if err2 == sql.ErrTxDone {
return
}
err = Errors{err, err2}
}
} else {
if err = tx.Commit(); err == sql.ErrTxDone {
err = nil
}
}
}()
err = f(tx)
return err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"TransactionalContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"sql",
".",
"TxOptions",
",",
"f",
"func",
"(",
"*",
"Tx",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"tx",
",",
"err",
":=... | // TransactionalContext starts a transaction and executes the given function with the given context and transaction options.
// If the function returns an error, the transaction will be rolled back.
// Otherwise, the transaction will be committed. | [
"TransactionalContext",
"starts",
"a",
"transaction",
"and",
"executes",
"the",
"given",
"function",
"with",
"the",
"given",
"context",
"and",
"transaction",
"options",
".",
"If",
"the",
"function",
"returns",
"an",
"error",
"the",
"transaction",
"will",
"be",
"... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L184-L211 |
13,991 | go-ozzo/ozzo-dbx | db.go | QuoteTableName | func (db *DB) QuoteTableName(s string) string {
if strings.Contains(s, "(") || strings.Contains(s, "{{") {
return s
}
if !strings.Contains(s, ".") {
return db.QuoteSimpleTableName(s)
}
parts := strings.Split(s, ".")
for i, part := range parts {
parts[i] = db.QuoteSimpleTableName(part)
}
return strings.Join(parts, ".")
} | go | func (db *DB) QuoteTableName(s string) string {
if strings.Contains(s, "(") || strings.Contains(s, "{{") {
return s
}
if !strings.Contains(s, ".") {
return db.QuoteSimpleTableName(s)
}
parts := strings.Split(s, ".")
for i, part := range parts {
parts[i] = db.QuoteSimpleTableName(part)
}
return strings.Join(parts, ".")
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"QuoteTableName",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"strings",
".",
"Contains",
"(",
"s",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"s",
",",
"\"",
"\"",
")",
"{",
"return",
"s",
... | // QuoteTableName quotes the given table name appropriately.
// If the table name contains DB schema prefix, it will be handled accordingly.
// This method will do nothing if the table name is already quoted or if it contains parenthesis. | [
"QuoteTableName",
"quotes",
"the",
"given",
"table",
"name",
"appropriately",
".",
"If",
"the",
"table",
"name",
"contains",
"DB",
"schema",
"prefix",
"it",
"will",
"be",
"handled",
"accordingly",
".",
"This",
"method",
"will",
"do",
"nothing",
"if",
"the",
... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L221-L233 |
13,992 | go-ozzo/ozzo-dbx | db.go | QuoteColumnName | func (db *DB) QuoteColumnName(s string) string {
if strings.Contains(s, "(") || strings.Contains(s, "{{") || strings.Contains(s, "[[") {
return s
}
prefix := ""
if pos := strings.LastIndex(s, "."); pos != -1 {
prefix = db.QuoteTableName(s[:pos]) + "."
s = s[pos+1:]
}
return prefix + db.QuoteSimpleColumnName(s)
} | go | func (db *DB) QuoteColumnName(s string) string {
if strings.Contains(s, "(") || strings.Contains(s, "{{") || strings.Contains(s, "[[") {
return s
}
prefix := ""
if pos := strings.LastIndex(s, "."); pos != -1 {
prefix = db.QuoteTableName(s[:pos]) + "."
s = s[pos+1:]
}
return prefix + db.QuoteSimpleColumnName(s)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"QuoteColumnName",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"strings",
".",
"Contains",
"(",
"s",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"s",
",",
"\"",
"\"",
")",
"||",
"strings",
"."... | // QuoteColumnName quotes the given column name appropriately.
// If the table name contains table name prefix, it will be handled accordingly.
// This method will do nothing if the column name is already quoted or if it contains parenthesis. | [
"QuoteColumnName",
"quotes",
"the",
"given",
"column",
"name",
"appropriately",
".",
"If",
"the",
"table",
"name",
"contains",
"table",
"name",
"prefix",
"it",
"will",
"be",
"handled",
"accordingly",
".",
"This",
"method",
"will",
"do",
"nothing",
"if",
"the",... | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L238-L248 |
13,993 | go-ozzo/ozzo-dbx | db.go | newBuilder | func (db *DB) newBuilder(executor Executor) Builder {
builderFunc, ok := BuilderFuncMap[db.driverName]
if !ok {
builderFunc = NewStandardBuilder
}
return builderFunc(db, executor)
} | go | func (db *DB) newBuilder(executor Executor) Builder {
builderFunc, ok := BuilderFuncMap[db.driverName]
if !ok {
builderFunc = NewStandardBuilder
}
return builderFunc(db, executor)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"newBuilder",
"(",
"executor",
"Executor",
")",
"Builder",
"{",
"builderFunc",
",",
"ok",
":=",
"BuilderFuncMap",
"[",
"db",
".",
"driverName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"builderFunc",
"=",
"NewStandardBuilder",
... | // newBuilder creates a query builder based on the current driver name. | [
"newBuilder",
"creates",
"a",
"query",
"builder",
"based",
"on",
"the",
"current",
"driver",
"name",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/db.go#L276-L282 |
13,994 | go-ozzo/ozzo-dbx | model_query.go | Delete | func (q *ModelQuery) Delete() error {
if q.lastError != nil {
return q.lastError
}
pk := q.model.pk()
if len(pk) == 0 {
return MissingPKError
}
_, err := q.builder.Delete(q.model.tableName, HashExp(pk)).WithContext(q.ctx).Execute()
return err
} | go | func (q *ModelQuery) Delete() error {
if q.lastError != nil {
return q.lastError
}
pk := q.model.pk()
if len(pk) == 0 {
return MissingPKError
}
_, err := q.builder.Delete(q.model.tableName, HashExp(pk)).WithContext(q.ctx).Execute()
return err
} | [
"func",
"(",
"q",
"*",
"ModelQuery",
")",
"Delete",
"(",
")",
"error",
"{",
"if",
"q",
".",
"lastError",
"!=",
"nil",
"{",
"return",
"q",
".",
"lastError",
"\n",
"}",
"\n",
"pk",
":=",
"q",
".",
"model",
".",
"pk",
"(",
")",
"\n",
"if",
"len",
... | // Delete deletes a row in the table using the primary key specified by the struct model associated with this query. | [
"Delete",
"deletes",
"a",
"row",
"in",
"the",
"table",
"using",
"the",
"primary",
"key",
"specified",
"by",
"the",
"struct",
"model",
"associated",
"with",
"this",
"query",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/model_query.go#L164-L174 |
13,995 | go-ozzo/ozzo-dbx | builder_standard.go | NewStandardBuilder | func NewStandardBuilder(db *DB, executor Executor) Builder {
return &StandardBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | go | func NewStandardBuilder(db *DB, executor Executor) Builder {
return &StandardBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | [
"func",
"NewStandardBuilder",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
")",
"Builder",
"{",
"return",
"&",
"StandardBuilder",
"{",
"NewBaseBuilder",
"(",
"db",
",",
"executor",
")",
",",
"NewBaseQueryBuilder",
"(",
"db",
")",
",",
"}",
"\n",
"}"
... | // NewStandardBuilder creates a new StandardBuilder instance. | [
"NewStandardBuilder",
"creates",
"a",
"new",
"StandardBuilder",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_standard.go#L16-L21 |
13,996 | go-ozzo/ozzo-dbx | builder_sqlite.go | NewSqliteBuilder | func NewSqliteBuilder(db *DB, executor Executor) Builder {
return &SqliteBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | go | func NewSqliteBuilder(db *DB, executor Executor) Builder {
return &SqliteBuilder{
NewBaseBuilder(db, executor),
NewBaseQueryBuilder(db),
}
} | [
"func",
"NewSqliteBuilder",
"(",
"db",
"*",
"DB",
",",
"executor",
"Executor",
")",
"Builder",
"{",
"return",
"&",
"SqliteBuilder",
"{",
"NewBaseBuilder",
"(",
"db",
",",
"executor",
")",
",",
"NewBaseQueryBuilder",
"(",
"db",
")",
",",
"}",
"\n",
"}"
] | // NewSqliteBuilder creates a new SqliteBuilder instance. | [
"NewSqliteBuilder",
"creates",
"a",
"new",
"SqliteBuilder",
"instance",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_sqlite.go#L22-L27 |
13,997 | go-ozzo/ozzo-dbx | builder_sqlite.go | DropColumn | func (b *SqliteBuilder) DropColumn(table, col string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support dropping columns")
return q
} | go | func (b *SqliteBuilder) DropColumn(table, col string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support dropping columns")
return q
} | [
"func",
"(",
"b",
"*",
"SqliteBuilder",
")",
"DropColumn",
"(",
"table",
",",
"col",
"string",
")",
"*",
"Query",
"{",
"q",
":=",
"b",
".",
"NewQuery",
"(",
"\"",
"\"",
")",
"\n",
"q",
".",
"LastError",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",... | // DropColumn creates a Query that can be used to drop a column from a table. | [
"DropColumn",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"drop",
"a",
"column",
"from",
"a",
"table",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_sqlite.go#L78-L82 |
13,998 | go-ozzo/ozzo-dbx | builder_sqlite.go | AlterColumn | func (b *SqliteBuilder) AlterColumn(table, col, typ string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support altering column")
return q
} | go | func (b *SqliteBuilder) AlterColumn(table, col, typ string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support altering column")
return q
} | [
"func",
"(",
"b",
"*",
"SqliteBuilder",
")",
"AlterColumn",
"(",
"table",
",",
"col",
",",
"typ",
"string",
")",
"*",
"Query",
"{",
"q",
":=",
"b",
".",
"NewQuery",
"(",
"\"",
"\"",
")",
"\n",
"q",
".",
"LastError",
"=",
"errors",
".",
"New",
"("... | // AlterColumn creates a Query that can be used to change the definition of a table column. | [
"AlterColumn",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"change",
"the",
"definition",
"of",
"a",
"table",
"column",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_sqlite.go#L92-L96 |
13,999 | go-ozzo/ozzo-dbx | builder_sqlite.go | DropPrimaryKey | func (b *SqliteBuilder) DropPrimaryKey(table, name string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support dropping primary key")
return q
} | go | func (b *SqliteBuilder) DropPrimaryKey(table, name string) *Query {
q := b.NewQuery("")
q.LastError = errors.New("SQLite does not support dropping primary key")
return q
} | [
"func",
"(",
"b",
"*",
"SqliteBuilder",
")",
"DropPrimaryKey",
"(",
"table",
",",
"name",
"string",
")",
"*",
"Query",
"{",
"q",
":=",
"b",
".",
"NewQuery",
"(",
"\"",
"\"",
")",
"\n",
"q",
".",
"LastError",
"=",
"errors",
".",
"New",
"(",
"\"",
... | // DropPrimaryKey creates a Query that can be used to remove the named primary key constraint from a table. | [
"DropPrimaryKey",
"creates",
"a",
"Query",
"that",
"can",
"be",
"used",
"to",
"remove",
"the",
"named",
"primary",
"key",
"constraint",
"from",
"a",
"table",
"."
] | e984ee904f1b2df904d0b2e6b2ca5064c87c0409 | https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/builder_sqlite.go#L107-L111 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.