8000 gocql/helpers.go at master · proforker/gocql · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"internal","path":"internal","contentType":"directory"},{"name":"testdata","path":"testdata","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"AUTHORS","path":"AUTHORS","contentType":"file"},{"name":"CONTRIBUTING.md","path":"CONTRIBUTING.md","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"batch_test.go","path":"batch_test.go","contentType":"file"},{"name":"cass1batch_test.go","path":"cass1batch_test.go","contentType":"file"},{"name":"cassandra_test.go","path":"cassandra_test.go","contentType":"file"},{"name":"cluster.go","path":"cluster.go","contentType":"file"},{"name":"common_test.go","path":"common_test.go","contentType":"file"},{"name":"compressor.go","path":"compressor.go","contentType":"file"},{"name":"compressor_test.go","path":"compressor_test.go","contentType":"file"},{"name":"conn.go","path":"conn.go","contentType":"file"},{"name":"conn_test.go","path":"conn_test.go","contentType":"file"},{"name":"connectionpool.go","path":"connectionpool.go","contentType":"file"},{"name":"control.go","path":"control.go","contentType":"file"},{"name":"debug_off.go","path":"debug_off.go","contentType":"file"},{"name":"debug_on.go","path":"debug_on.go","contentType":"file"},{"name":"doc.go","path":"doc.go","contentType":"file"},{"name":"errors.go","path":"errors.go","contentType":"file"},{"name":"errors_test.go","path":"errors_test.go","contentType":"file"},{"name":"events.go","path":"events.go","contentType":"file"},{"name":"events_ccm_test.go","path":"events_ccm_test.go","contentType":"file"},{"name":"events_test.go","path":"events_test.go","contentType":"file"},{"name":"filters.go","path":"filters.go","contentType":"file"},{"name":"filters_test.go","path":"filters_test.go","contentType":"file"},{"name":"frame.go","path":"frame.go","contentType":"file"},{"name":"frame_test.go","path":"frame_test.go","contentType":"file"},{"name":"framer_bench_test.go","path":"framer_bench_test.go","contentType":"file"},{"name":"fuzz.go","path":"fuzz.go","contentType":"file"},{"name":"helpers.go","path":"helpers.go","contentType":"file"},{"name":"host_source.go","path":"host_source.go","contentType":"file"},{"name":"host_source_test.go","path":"host_source_test.go","contentType":"file"},{"name":"integration.sh","path":"integration.sh","contentType":"file"},{"name":"marshal.go","path":"marshal.go","contentType":"file"},{"name":"marshal_test.go","path":"marshal_test.go","contentType":"file"},{"name":"metadata.go","path":"metadata.go","contentType":"file"},{"name":"metadata_test.go","path":"metadata_test.go","contentType":"file"},{"name":"policies.go","path":"policies.go","contentType":"file"},{"name":"policies_test.go","path":"policies_test.go","contentType":"file"},{"name":"prepared_cache.go","path":"prepared_cache.go","contentType":"file"},{"name":"query_executor.go","path":"query_executor.go","contentType":"file"},{"name":"ring.go","path":"ring.go","contentType":"file"},{"name":"ring_test.go","path":"ring_test.go","contentType":"file"},{"name":"session.go","path":"session.go","contentType":"file"},{"name":"session_test.go","path":"session_test.go","contentType":"file"},{"name":"stress_test.go","path":"stress_test.go","contentType":"file"},{"name":"token.go","path":"token.go","contentType":"file"},{"name":"token_test.go","path":"token_test.go","contentType":"file"},{"name":"topology.go","path":"topology.go","contentType":"file"},{"name":"topology_test.go","path":"topology_test.go","contentType":"file"},{"name":"tuple_test.go","path":"tuple_test.go","contentType":"file"},{"name":"udt_test.go","path":"udt_test.go","contentType":"file"},{"name":"uuid.go","path":"uuid.go","contentType":"file"},{"name":"uuid_test.go","path":"uuid_test.go","contentType":"file"},{"name":"wiki_test.go","path":"wiki_test.go","contentType":"file"}],"totalCount":59}},"fileTreeProcessingTime":12.01269,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":69199247,"defaultBranch":"master","name":"gocql","ownerLogin":"proforker","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2016-09-26T00:35:52.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/22436249?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1615951776.92827","canEdit":false,"refType":"branch","currentOid":"89e1c0f309816323d37394c9f7a4a918301f609f"},"path":"helpers.go","currentUser":null,"blob":{"rawLines":["// Copyright (c) 2012 The gocql Authors. All rights reserved.","// Use of this source code is governed by a BSD-style","// license that can be found in the LICENSE file.","","package gocql","","import (","\t\"fmt\"","\t\"math/big\"","\t\"reflect\"","\t\"strings\"","\t\"time\"","","\t\"gopkg.in/inf.v0\"",")","","type RowData struct {","\tColumns []string","\tValues []interface{}","}","","func goType(t TypeInfo) reflect.Type {","\tswitch t.Type() {","\tcase TypeVarchar, TypeAscii, TypeInet, TypeText:","\t\treturn reflect.TypeOf(*new(string))","\tcase TypeBigInt, TypeCounter:","\t\treturn reflect.TypeOf(*new(int64))","\tcase TypeTimestamp:","\t\treturn reflect.TypeOf(*new(time.Time))","\tcase TypeBlob:","\t\treturn reflect.TypeOf(*new([]byte))","\tcase TypeBoolean:","\t\treturn reflect.TypeOf(*new(bool))","\tcase TypeFloat:","\t\treturn reflect.TypeOf(*new(float32))","\tcase TypeDouble:","\t\treturn reflect.TypeOf(*new(float64))","\tcase TypeInt:","\t\treturn reflect.TypeOf(*new(int))","\tcase TypeSmallInt:","\t\treturn reflect.TypeOf(*new(int16))","\tcase TypeDecimal:","\t\treturn reflect.TypeOf(*new(*inf.Dec))","\tcase TypeUUID, TypeTimeUUID:","\t\treturn reflect.TypeOf(*new(UUID))","\tcase TypeList, TypeSet:","\t\treturn reflect.SliceOf(goType(t.(CollectionType).Elem))","\tcase TypeMap:","\t\treturn reflect.MapOf(goType(t.(CollectionType).Key), goType(t.(CollectionType).Elem))","\tcase TypeVarint:","\t\treturn reflect.TypeOf(*new(*big.Int))","\tcase TypeTuple:","\t\t// what can we do here? all there is to do is to make a list of interface{}","\t\ttuple := t.(TupleTypeInfo)","\t\treturn reflect.TypeOf(make([]interface{}, len(tuple.Elems)))","\tcase TypeUDT:","\t\treturn reflect.TypeOf(make(map[string]interface{}))","\tdefault:","\t\treturn nil","\t}","}","","func dereference(i interface{}) interface{} {","\treturn reflect.Indirect(reflect.ValueOf(i)).Interface()","}","","func getCassandraType(name string) Type {","\tswitch name {","\tcase \"ascii\":","\t\treturn TypeAscii","\tcase \"bigint\":","\t\treturn TypeBigInt","\tcase \"blob\":","\t\treturn TypeBlob","\tcase \"boolean\":","\t\treturn TypeBoolean","\tcase \"counter\":","\t\treturn TypeCounter","\tcase \"decimal\":","\t\treturn TypeDecimal","\tcase \"double\":","\t\treturn TypeDouble","\tcase \"float\":","\t\treturn TypeFloat","\tcase \"int\":","\t\treturn TypeInt","\tcase \"timestamp\":","\t\treturn TypeTimestamp","\tcase \"uuid\":","\t\treturn TypeUUID","\tcase \"varchar\", \"text\":","\t\treturn TypeVarchar","\tcase \"varint\":","\t\treturn TypeVarint","\tcase \"timeuuid\":","\t\treturn TypeTimeUUID","\tcase \"inet\":","\t\treturn TypeInet","\tcase \"MapType\":","\t\treturn TypeMap","\tcase \"ListType\":","\t\treturn TypeList","\tcase \"SetType\":","\t\treturn TypeSet","\tcase \"TupleType\":","\t\treturn TypeTuple","\tdefault:","\t\tif strings.HasPrefix(name, \"set\") {","\t\t\treturn TypeSet","\t\t} else if strings.HasPrefix(name, \"list\") {","\t\t\treturn TypeList","\t\t} else if strings.HasPrefix(name, \"map\") {","\t\t\treturn TypeMap","\t\t} else if strings.HasPrefix(name, \"tuple\") {","\t\t\treturn TypeTuple","\t\t}","\t\treturn TypeCustom","\t}","}","","func getApacheCassandraType(class string) Type {","\tswitch strings.TrimPrefix(class, apacheCassandraTypePrefix) {","\tcase \"AsciiType\":","\t\treturn TypeAscii","\tcase \"LongType\":","\t\treturn TypeBigInt","\tcase \"BytesType\":","\t\treturn TypeBlob","\tcase \"BooleanType\":","\t\treturn TypeBoolean","\tcase \"CounterColumnType\":","\t\treturn TypeCounter","\tcase \"DecimalType\":","\t\treturn TypeDecimal","\tcase \"DoubleType\":","\t\treturn TypeDouble","\tcase \"FloatType\":","\t\treturn TypeFloat","\tcase \"Int32Type\":","\t\treturn TypeInt","\tcase \"ShortType\":","\t\treturn TypeSmallInt","\tcase \"ByteType\":","\t\treturn TypeTinyInt","\tcase \"DateType\", \"TimestampType\":","\t\treturn TypeTimestamp","\tcase \"UUIDType\", \"LexicalUUIDType\":","\t\treturn TypeUUID","\tcase \"UTF8Type\":","\t\treturn TypeVarchar","\tcase \"IntegerType\":","\t\treturn TypeVarint","\tcase \"TimeUUIDType\":","\t\treturn TypeTimeUUID","\tcase \"InetAddressType\":","\t\treturn TypeInet","\tcase \"MapType\":","\t\treturn TypeMap","\tcase \"ListType\":","\t\treturn TypeList","\tcase \"SetType\":","\t\treturn TypeSet","\tcase \"TupleType\":","\t\treturn TypeTuple","\tdefault:","\t\treturn TypeCustom","\t}","}","","func typeCanBeNull(typ TypeInfo) bool {","\tswitch typ.(type) {","\tcase CollectionType, UDTTypeInfo, TupleTypeInfo:","\t\treturn false","\t}","","\treturn true","}","","func (r *RowData) rowMap(m map[string]interface{}) {","\tfor i, column := range r.Columns {","\t\tval := dereference(r.Values[i])","\t\tif valVal := reflect.ValueOf(val); valVal.Kind() == reflect.Slice {","\t\t\tvalCopy := reflect.MakeSlice(valVal.Type(), valVal.Len(), valVal.Cap())","\t\t\treflect.Copy(valCopy, valVal)","\t\t\tm[column] = valCopy.Interface()","\t\t} else {","\t\t\tm[column] = val","\t\t}","\t}","}","","// TupeColumnName will return the column name of a tuple value in a column named","// c at index n. It should be used if a specific element within a tuple is needed","// to be extracted from a map returned from SliceMap or MapScan.","func TupleColumnName(c string, n int) string {","\treturn fmt.Sprintf(\"%s[%d]\", c, n)","}","","func (iter *Iter) RowData() (RowData, error) {","\tif iter.err != nil {","\t\treturn RowData{}, iter.err","\t}","","\tcolumns := make([]string, 0)","\tvalues := make([]interface{}, 0)","","\tfor _, column := range iter.Columns() {","","\t\tswitch c := column.TypeInfo.(type) {","\t\tcase TupleTypeInfo:","\t\t\tfor i, elem := range c.Elems {","\t\t\t\tcolumns = append(columns, TupleColumnName(column.Name, i))","\t\t\t\tvalues = append(values, elem.New())","\t\t\t}","\t\tdefault:","\t\t\tval := column.TypeInfo.New()","\t\t\tcolumns = append(columns, column.Name)","\t\t\tvalues = append(values, val)","\t\t}","\t}","\trowData := RowData{","\t\tColumns: columns,","\t\tValues: values,","\t}","\treturn rowData, nil","}","","// SliceMap is a helper function to make the API easier to use","// returns the data from the query in the form of []map[string]interface{}","func (iter *Iter) SliceMap() ([]map[string]interface{}, error) {","\tif iter.err != nil {","\t\treturn nil, iter.err","\t}","","\t// Not checking for the error because we just did","\trowData, _ := iter.RowData()","\tdataToReturn := make([]map[string]interface{}, 0)","\tfor iter.Scan(rowData.Values...) {","\t\tm := make(map[string]interface{})","\t\trowData.rowMap(m)","\t\tdataToReturn = append(dataToReturn, m)","\t}","\tif iter.err != nil {","\t\treturn nil, iter.err","\t}","\treturn dataToReturn, nil","}","","// MapScan takes a map[string]interface{} and populates it with a row","// that is returned from cassandra.","func (iter *Iter) MapScan(m map[string]interface{}) bool {","\tif iter.err != nil {","\t\treturn false","\t}","","\t// Not checking for the error because we just did","\trowData, _ := iter.RowData()","","\tfor i, col := range rowData.Columns {","\t\tif dest, ok := m[col]; ok {","\t\t\trowData.Values[i] = dest","\t\t}","\t}","","\tif iter.Scan(rowData.Values...) {","\t\trowData.rowMap(m)","\t\treturn true","\t}","\treturn false","}","","func copyBytes(p []byte) []byte {","\tb := make([]byte, len(p))","\tcopy(b, p)","\treturn b","}"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/proforker/gocql/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"helpers.go","displayUrl":"https://github.com/proforker/gocql/blob/master/helpers.go?raw=true","headerInfo":{"blobSize":"6.21 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"084d8ff","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fproforker%2Fgocql%2Fblob%2Fmaster%2Fhelpers.go","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"276","truncatedSloc":"253"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Go","languageID":132,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/proforker/gocql/blob/master/helpers.go","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/proforker/gocql/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/proforker/gocql/raw/refs/heads/master/helpers.go","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":{"timed_out":false,"not_analyzed":false,"symbols":[{"name":"RowData","kind":"class","ident_start":268,"ident_end":275,"extent_start":263,"extent_end":327,"fully_qualified_name":"RowData","ident_utf16":{"start":{"line_number":16,"utf16_col":5},"end":{"line_number":16,"utf16_col":12}},"extent_utf16":{"start":{"line_number":16,"utf16_col":0},"end":{"line_number":19,"utf16_col":1}}},{"name":"Columns","kind":"field","ident_start":286,"ident_end":293,"extent_start":286,"extent_end":302,"fully_qualified_name":"RowData.Columns","ident_utf16":{"start":{"line_number":17,"utf16_col":1},"end":{"line_number":17,"utf16_col":8}},"extent_utf16":{"start":{"line_number":17,"utf16_col":1},"end":{"line_number":17,"utf16_col":17}}},{"name":"Values","kind":"field","ident_start":304,"ident_end":310,"extent_start":304,"extent_end":325,"fully_qualified_name":"RowData.Values","ident_utf16":{"start":{"line_number":18,"utf16_col":1},"end":{"line_number":18,"utf16_col":7}},"extent_utf16":{"start":{"line_number":18,"utf16_col":1},"end":{"line_number":18,"utf16_col":22}}},{"name":"goType","kind":"function","ident_start":334,"ident_end":340,"extent_start":329,"extent_end":1586,"fully_qualified_name":"goType","ident_utf16":{"start":{"line_number":21,"utf16_col":5},"end":{"line_number":21,"utf16_col":11}},"extent_utf16":{"start":{"line_number":21,"utf16_col":0},"end":{"line_number":60,"utf16_col":1}}},{"name":"dereference","kind":"function","ident_start":1593,"ident_end":1604,"extent_start":1588,"extent_end":1692,"fully_qualified_name":"dereference","ident_utf16":{"start":{"line_number":62,"utf16_col":5},"end":{"line_number":62,"utf16_col":16}},"extent_utf16":{"start":{"line_number":62,"utf16_col":0},"end":{"line_number":64,"utf16_col":1}}},{"name":"getCassandraType","kind":"function","ident_start":1699,"ident_end":1715,"extent_start":1694,"extent_end":2726,"fully_qualified_name":"getCassandraType","ident_utf16":{"start":{"line_number":66,"utf16_col":5},"end":{"line_number":66,"utf16_col":21}},"extent_utf16":{"start":{"line_number":66,"utf16_col":0},"end":{"line_number":118,"utf16_col":1}}},{"name":"getApacheCassandraType","kind":"function","ident_start":2733,"ident_end":2755,"extent_start":2728,"extent_end":3735,"fully_qualified_name":"getApacheCassandraType","ident_utf16":{"start":{"line_number":120,"utf16_col":5},"end":{"line_number":120,"utf16_col":27}},"extent_utf16":{"start":{"line_number":120,"utf16_col":0},"end":{"line_number":167,"utf16_col":1}}},{"name":"typeCanBeNull","kind":"function","ident_start":3742,"ident_end":3755,"extent_start":3737,"extent_end":3881,"fully_qualified_name":"typeCanBeNull","ident_utf16":{"start":{"line_number":169,"utf16_col":5},"end":{"line_number":169,"utf16_col":18}},"extent_utf16":{"start":{"line_number":169,"utf16_col":0},"end":{"line_number":176,"utf16_col":1}}},{"name":"rowMap","kind":"method","ident_start":3901,"ident_end":3907,"extent_start":3883,"extent_end":4257,"fully_qualified_name":"RowData.rowMap","ident_utf16":{"start":{"line_number":178,"utf16_col":18},"end":{"line_number":178,"utf16_col":24}},"extent_utf16":{"start":{"line_number":178,"utf16_col":0},"end":{"line_number":189,"utf16_col":1}}},{"name":"TupleColumnName","kind":"function","ident_start":4492,"ident_end":4507,"extent_start":4487,"extent_end":4571,"fully_qualified_name":"TupleColumnName","ident_utf16":{"start":{"line_number":194,"utf16_col":5},"end":{"line_number":194,"utf16_col":20}},"extent_utf16":{"start":{"line_number":194,"utf16_col":0},"end":{"line_number":196,"utf16_col":1}}},{"name":"RowData","kind":"method","ident_start":4591,"ident_end":4598,"extent_start":4573,"extent_end":5194,"fully_qualified_name":"Iter.RowData","ident_utf16":{"start":{"line_number":198,"utf16_col":18},"end":{"line_number":198,"utf16_col":25}},"extent_utf16":{"start":{"line_number":198,"utf16_col":0},"end":{"line_number":225,"utf16_col":1}}},{"name":"SliceMap","kind":"method","ident_start":5352,"ident_end":5360,"extent_start":5334,"extent_end":5791,"fully_qualified_name":"Iter.SliceMap","ident_utf16":{"start":{"line_number":229,"utf16_col":18},"end":{"line_number":229,"utf16_col":26}},"extent_utf16":{"start":{"line_number":229,"utf16_col":0},"end":{"line_number":246,"utf16_col":1}}},{"name":"MapScan","kind":"method","ident_start":5917,"ident_end":5924,"extent_start":5899,"extent_end":6273,"fully_qualified_name":"Iter.MapScan","ident_utf16":{"start":{"line_number":250,"utf16_col":18},"end":{"line_number":250,"utf16_col":25}},"extent_utf16":{"start":{"line_number":250,"utf16_col":0},"end":{"line_number":269,"utf16_col":1}}},{"name":"copyBytes","kind":"function","ident_start":6280,"ident_end":6289,"extent_start":6275,"extent_end":6359,"fully_qualified_name":"copyBytes","ident_utf16":{"start":{"line_number":271,"utf16_col":5},"end":{"line_number":271,"utf16_col":14}},"extent_utf16":{"start":{"line_number":271,"utf16_col":0},"end":{"line_number":275,"utf16_col":1}}}]}},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/proforker/gocql/branches":{"post":"Lp1HmI8M7CJ4rCW5KeOga2Qn9_p_TMoGHuP0oxH8kEJjLygeB9HuTdfkMplZARnniRRl7eU0fCYpcgpdqbhBYQ"},"/repos/preferences":{"post":"5Jt-SQSjN2GbyG_fFibDCcakjzbjQ5LzX6AT-0p-H49f9aiTd0o1JQh8CGpHVaQkDg-52VDIsWnmL9PT1wVjhQ"}}},"title":"gocql/helpers.go at master · proforker/gocql","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-7d7eb7c71814.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-1ae9fa256942.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true,"github_models_repo_integration":false}}}
0