You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

309 lines
5.9 KiB

  1. // Copyright 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by gapic-generator. DO NOT EDIT.
  15. package spanner_test
  16. import (
  17. "context"
  18. "io"
  19. spanner "cloud.google.com/go/spanner/apiv1"
  20. "google.golang.org/api/iterator"
  21. spannerpb "google.golang.org/genproto/googleapis/spanner/v1"
  22. )
  23. func ExampleNewClient() {
  24. ctx := context.Background()
  25. c, err := spanner.NewClient(ctx)
  26. if err != nil {
  27. // TODO: Handle error.
  28. }
  29. // TODO: Use client.
  30. _ = c
  31. }
  32. func ExampleClient_CreateSession() {
  33. ctx := context.Background()
  34. c, err := spanner.NewClient(ctx)
  35. if err != nil {
  36. // TODO: Handle error.
  37. }
  38. req := &spannerpb.CreateSessionRequest{
  39. // TODO: Fill request struct fields.
  40. }
  41. resp, err := c.CreateSession(ctx, req)
  42. if err != nil {
  43. // TODO: Handle error.
  44. }
  45. // TODO: Use resp.
  46. _ = resp
  47. }
  48. func ExampleClient_GetSession() {
  49. ctx := context.Background()
  50. c, err := spanner.NewClient(ctx)
  51. if err != nil {
  52. // TODO: Handle error.
  53. }
  54. req := &spannerpb.GetSessionRequest{
  55. // TODO: Fill request struct fields.
  56. }
  57. resp, err := c.GetSession(ctx, req)
  58. if err != nil {
  59. // TODO: Handle error.
  60. }
  61. // TODO: Use resp.
  62. _ = resp
  63. }
  64. func ExampleClient_ListSessions() {
  65. ctx := context.Background()
  66. c, err := spanner.NewClient(ctx)
  67. if err != nil {
  68. // TODO: Handle error.
  69. }
  70. req := &spannerpb.ListSessionsRequest{
  71. // TODO: Fill request struct fields.
  72. }
  73. it := c.ListSessions(ctx, req)
  74. for {
  75. resp, err := it.Next()
  76. if err == iterator.Done {
  77. break
  78. }
  79. if err != nil {
  80. // TODO: Handle error.
  81. }
  82. // TODO: Use resp.
  83. _ = resp
  84. }
  85. }
  86. func ExampleClient_DeleteSession() {
  87. ctx := context.Background()
  88. c, err := spanner.NewClient(ctx)
  89. if err != nil {
  90. // TODO: Handle error.
  91. }
  92. req := &spannerpb.DeleteSessionRequest{
  93. // TODO: Fill request struct fields.
  94. }
  95. err = c.DeleteSession(ctx, req)
  96. if err != nil {
  97. // TODO: Handle error.
  98. }
  99. }
  100. func ExampleClient_ExecuteSql() {
  101. ctx := context.Background()
  102. c, err := spanner.NewClient(ctx)
  103. if err != nil {
  104. // TODO: Handle error.
  105. }
  106. req := &spannerpb.ExecuteSqlRequest{
  107. // TODO: Fill request struct fields.
  108. }
  109. resp, err := c.ExecuteSql(ctx, req)
  110. if err != nil {
  111. // TODO: Handle error.
  112. }
  113. // TODO: Use resp.
  114. _ = resp
  115. }
  116. func ExampleClient_ExecuteStreamingSql() {
  117. ctx := context.Background()
  118. c, err := spanner.NewClient(ctx)
  119. if err != nil {
  120. // TODO: Handle error.
  121. }
  122. req := &spannerpb.ExecuteSqlRequest{
  123. // TODO: Fill request struct fields.
  124. }
  125. stream, err := c.ExecuteStreamingSql(ctx, req)
  126. if err != nil {
  127. // TODO: Handle error.
  128. }
  129. for {
  130. resp, err := stream.Recv()
  131. if err == io.EOF {
  132. break
  133. }
  134. if err != nil {
  135. // TODO: handle error.
  136. }
  137. // TODO: Use resp.
  138. _ = resp
  139. }
  140. }
  141. func ExampleClient_ExecuteBatchDml() {
  142. ctx := context.Background()
  143. c, err := spanner.NewClient(ctx)
  144. if err != nil {
  145. // TODO: Handle error.
  146. }
  147. req := &spannerpb.ExecuteBatchDmlRequest{
  148. // TODO: Fill request struct fields.
  149. }
  150. resp, err := c.ExecuteBatchDml(ctx, req)
  151. if err != nil {
  152. // TODO: Handle error.
  153. }
  154. // TODO: Use resp.
  155. _ = resp
  156. }
  157. func ExampleClient_Read() {
  158. ctx := context.Background()
  159. c, err := spanner.NewClient(ctx)
  160. if err != nil {
  161. // TODO: Handle error.
  162. }
  163. req := &spannerpb.ReadRequest{
  164. // TODO: Fill request struct fields.
  165. }
  166. resp, err := c.Read(ctx, req)
  167. if err != nil {
  168. // TODO: Handle error.
  169. }
  170. // TODO: Use resp.
  171. _ = resp
  172. }
  173. func ExampleClient_StreamingRead() {
  174. ctx := context.Background()
  175. c, err := spanner.NewClient(ctx)
  176. if err != nil {
  177. // TODO: Handle error.
  178. }
  179. req := &spannerpb.ReadRequest{
  180. // TODO: Fill request struct fields.
  181. }
  182. stream, err := c.StreamingRead(ctx, req)
  183. if err != nil {
  184. // TODO: Handle error.
  185. }
  186. for {
  187. resp, err := stream.Recv()
  188. if err == io.EOF {
  189. break
  190. }
  191. if err != nil {
  192. // TODO: handle error.
  193. }
  194. // TODO: Use resp.
  195. _ = resp
  196. }
  197. }
  198. func ExampleClient_BeginTransaction() {
  199. ctx := context.Background()
  200. c, err := spanner.NewClient(ctx)
  201. if err != nil {
  202. // TODO: Handle error.
  203. }
  204. req := &spannerpb.BeginTransactionRequest{
  205. // TODO: Fill request struct fields.
  206. }
  207. resp, err := c.BeginTransaction(ctx, req)
  208. if err != nil {
  209. // TODO: Handle error.
  210. }
  211. // TODO: Use resp.
  212. _ = resp
  213. }
  214. func ExampleClient_Commit() {
  215. ctx := context.Background()
  216. c, err := spanner.NewClient(ctx)
  217. if err != nil {
  218. // TODO: Handle error.
  219. }
  220. req := &spannerpb.CommitRequest{
  221. // TODO: Fill request struct fields.
  222. }
  223. resp, err := c.Commit(ctx, req)
  224. if err != nil {
  225. // TODO: Handle error.
  226. }
  227. // TODO: Use resp.
  228. _ = resp
  229. }
  230. func ExampleClient_Rollback() {
  231. ctx := context.Background()
  232. c, err := spanner.NewClient(ctx)
  233. if err != nil {
  234. // TODO: Handle error.
  235. }
  236. req := &spannerpb.RollbackRequest{
  237. // TODO: Fill request struct fields.
  238. }
  239. err = c.Rollback(ctx, req)
  240. if err != nil {
  241. // TODO: Handle error.
  242. }
  243. }
  244. func ExampleClient_PartitionQuery() {
  245. ctx := context.Background()
  246. c, err := spanner.NewClient(ctx)
  247. if err != nil {
  248. // TODO: Handle error.
  249. }
  250. req := &spannerpb.PartitionQueryRequest{
  251. // TODO: Fill request struct fields.
  252. }
  253. resp, err := c.PartitionQuery(ctx, req)
  254. if err != nil {
  255. // TODO: Handle error.
  256. }
  257. // TODO: Use resp.
  258. _ = resp
  259. }
  260. func ExampleClient_PartitionRead() {
  261. ctx := context.Background()
  262. c, err := spanner.NewClient(ctx)
  263. if err != nil {
  264. // TODO: Handle error.
  265. }
  266. req := &spannerpb.PartitionReadRequest{
  267. // TODO: Fill request struct fields.
  268. }
  269. resp, err := c.PartitionRead(ctx, req)
  270. if err != nil {
  271. // TODO: Handle error.
  272. }
  273. // TODO: Use resp.
  274. _ = resp
  275. }