spanner_client.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. spannerpb "google.golang.org/genproto/googleapis/spanner/v1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // CallOptions contains the retry settings for each method of Client.
  31. type CallOptions struct {
  32. CreateSession []gax.CallOption
  33. GetSession []gax.CallOption
  34. ListSessions []gax.CallOption
  35. DeleteSession []gax.CallOption
  36. ExecuteSql []gax.CallOption
  37. ExecuteStreamingSql []gax.CallOption
  38. Read []gax.CallOption
  39. StreamingRead []gax.CallOption
  40. BeginTransaction []gax.CallOption
  41. Commit []gax.CallOption
  42. Rollback []gax.CallOption
  43. PartitionQuery []gax.CallOption
  44. PartitionRead []gax.CallOption
  45. }
  46. func defaultClientOptions() []option.ClientOption {
  47. return []option.ClientOption{
  48. option.WithEndpoint("spanner.googleapis.com:443"),
  49. option.WithScopes(DefaultAuthScopes()...),
  50. }
  51. }
  52. func defaultCallOptions() *CallOptions {
  53. retry := map[[2]string][]gax.CallOption{
  54. {"default", "idempotent"}: {
  55. gax.WithRetry(func() gax.Retryer {
  56. return gax.OnCodes([]codes.Code{
  57. codes.DeadlineExceeded,
  58. codes.Unavailable,
  59. }, gax.Backoff{
  60. Initial: 1000 * time.Millisecond,
  61. Max: 32000 * time.Millisecond,
  62. Multiplier: 1.3,
  63. })
  64. }),
  65. },
  66. {"long_running", "long_running"}: {
  67. gax.WithRetry(func() gax.Retryer {
  68. return gax.OnCodes([]codes.Code{
  69. codes.Unavailable,
  70. }, gax.Backoff{
  71. Initial: 1000 * time.Millisecond,
  72. Max: 32000 * time.Millisecond,
  73. Multiplier: 1.3,
  74. })
  75. }),
  76. },
  77. }
  78. return &CallOptions{
  79. CreateSession: retry[[2]string{"default", "idempotent"}],
  80. GetSession: retry[[2]string{"default", "idempotent"}],
  81. ListSessions: retry[[2]string{"default", "idempotent"}],
  82. DeleteSession: retry[[2]string{"default", "idempotent"}],
  83. ExecuteSql: retry[[2]string{"default", "idempotent"}],
  84. ExecuteStreamingSql: retry[[2]string{"streaming", "non_idempotent"}],
  85. Read: retry[[2]string{"default", "idempotent"}],
  86. StreamingRead: retry[[2]string{"streaming", "non_idempotent"}],
  87. BeginTransaction: retry[[2]string{"default", "idempotent"}],
  88. Commit: retry[[2]string{"long_running", "long_running"}],
  89. Rollback: retry[[2]string{"default", "idempotent"}],
  90. PartitionQuery: retry[[2]string{"default", "idempotent"}],
  91. PartitionRead: retry[[2]string{"default", "idempotent"}],
  92. }
  93. }
  94. // Client is a client for interacting with Cloud Spanner API.
  95. //
  96. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  97. type Client struct {
  98. // The connection to the service.
  99. conn *grpc.ClientConn
  100. // The gRPC API client.
  101. client spannerpb.SpannerClient
  102. // The call options for this service.
  103. CallOptions *CallOptions
  104. // The x-goog-* metadata to be sent with each request.
  105. xGoogMetadata metadata.MD
  106. }
  107. // NewClient creates a new spanner client.
  108. //
  109. // Cloud Spanner API
  110. //
  111. // The Cloud Spanner API can be used to manage sessions and execute
  112. // transactions on data stored in Cloud Spanner databases.
  113. func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
  114. conn, err := transport.DialGRPC(ctx, append(defaultClientOptions(), opts...)...)
  115. if err != nil {
  116. return nil, err
  117. }
  118. c := &Client{
  119. conn: conn,
  120. CallOptions: defaultCallOptions(),
  121. client: spannerpb.NewSpannerClient(conn),
  122. }
  123. c.SetGoogleClientInfo()
  124. return c, nil
  125. }
  126. // Connection returns the client's connection to the API service.
  127. func (c *Client) Connection() *grpc.ClientConn {
  128. return c.conn
  129. }
  130. // Close closes the connection to the API service. The user should invoke this when
  131. // the client is no longer required.
  132. func (c *Client) Close() error {
  133. return c.conn.Close()
  134. }
  135. // SetGoogleClientInfo sets the name and version of the application in
  136. // the `x-goog-api-client` header passed on each request. Intended for
  137. // use by Google-written clients.
  138. func (c *Client) SetGoogleClientInfo(keyval ...string) {
  139. kv := append([]string{"gl-go", versionGo()}, keyval...)
  140. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  141. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  142. }
  143. // CreateSession creates a new session. A session can be used to perform
  144. // transactions that read and/or modify data in a Cloud Spanner database.
  145. // Sessions are meant to be reused for many consecutive
  146. // transactions.
  147. //
  148. // Sessions can only execute one transaction at a time. To execute
  149. // multiple concurrent read-write/write-only transactions, create
  150. // multiple sessions. Note that standalone reads and queries use a
  151. // transaction internally, and count toward the one transaction
  152. // limit.
  153. //
  154. // Cloud Spanner limits the number of sessions that can exist at any given
  155. // time; thus, it is a good idea to delete idle and/or unneeded sessions.
  156. // Aside from explicit deletes, Cloud Spanner can delete sessions for which no
  157. // operations are sent for more than an hour. If a session is deleted,
  158. // requests to it return NOT_FOUND.
  159. //
  160. // Idle sessions can be kept alive by sending a trivial SQL query
  161. // periodically, e.g., "SELECT 1".
  162. func (c *Client) CreateSession(ctx context.Context, req *spannerpb.CreateSessionRequest, opts ...gax.CallOption) (*spannerpb.Session, error) {
  163. ctx = insertMetadata(ctx, c.xGoogMetadata)
  164. opts = append(c.CallOptions.CreateSession[0:len(c.CallOptions.CreateSession):len(c.CallOptions.CreateSession)], opts...)
  165. var resp *spannerpb.Session
  166. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  167. var err error
  168. resp, err = c.client.CreateSession(ctx, req, settings.GRPC...)
  169. return err
  170. }, opts...)
  171. if err != nil {
  172. return nil, err
  173. }
  174. return resp, nil
  175. }
  176. // GetSession gets a session. Returns NOT_FOUND if the session does not exist.
  177. // This is mainly useful for determining whether a session is still
  178. // alive.
  179. func (c *Client) GetSession(ctx context.Context, req *spannerpb.GetSessionRequest, opts ...gax.CallOption) (*spannerpb.Session, error) {
  180. ctx = insertMetadata(ctx, c.xGoogMetadata)
  181. opts = append(c.CallOptions.GetSession[0:len(c.CallOptions.GetSession):len(c.CallOptions.GetSession)], opts...)
  182. var resp *spannerpb.Session
  183. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  184. var err error
  185. resp, err = c.client.GetSession(ctx, req, settings.GRPC...)
  186. return err
  187. }, opts...)
  188. if err != nil {
  189. return nil, err
  190. }
  191. return resp, nil
  192. }
  193. // ListSessions lists all sessions in a given database.
  194. func (c *Client) ListSessions(ctx context.Context, req *spannerpb.ListSessionsRequest, opts ...gax.CallOption) *SessionIterator {
  195. ctx = insertMetadata(ctx, c.xGoogMetadata)
  196. opts = append(c.CallOptions.ListSessions[0:len(c.CallOptions.ListSessions):len(c.CallOptions.ListSessions)], opts...)
  197. it := &SessionIterator{}
  198. req = proto.Clone(req).(*spannerpb.ListSessionsRequest)
  199. it.InternalFetch = func(pageSize int, pageToken string) ([]*spannerpb.Session, string, error) {
  200. var resp *spannerpb.ListSessionsResponse
  201. req.PageToken = pageToken
  202. if pageSize > math.MaxInt32 {
  203. req.PageSize = math.MaxInt32
  204. } else {
  205. req.PageSize = int32(pageSize)
  206. }
  207. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  208. var err error
  209. resp, err = c.client.ListSessions(ctx, req, settings.GRPC...)
  210. return err
  211. }, opts...)
  212. if err != nil {
  213. return nil, "", err
  214. }
  215. return resp.Sessions, resp.NextPageToken, nil
  216. }
  217. fetch := func(pageSize int, pageToken string) (string, error) {
  218. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  219. if err != nil {
  220. return "", err
  221. }
  222. it.items = append(it.items, items...)
  223. return nextPageToken, nil
  224. }
  225. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  226. it.pageInfo.MaxSize = int(req.PageSize)
  227. return it
  228. }
  229. // DeleteSession ends a session, releasing server resources associated with it.
  230. func (c *Client) DeleteSession(ctx context.Context, req *spannerpb.DeleteSessionRequest, opts ...gax.CallOption) error {
  231. ctx = insertMetadata(ctx, c.xGoogMetadata)
  232. opts = append(c.CallOptions.DeleteSession[0:len(c.CallOptions.DeleteSession):len(c.CallOptions.DeleteSession)], opts...)
  233. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  234. var err error
  235. _, err = c.client.DeleteSession(ctx, req, settings.GRPC...)
  236. return err
  237. }, opts...)
  238. return err
  239. }
  240. // ExecuteSql executes an SQL statement, returning all results in a single reply. This
  241. // method cannot be used to return a result set larger than 10 MiB;
  242. // if the query yields more data than that, the query fails with
  243. // a FAILED_PRECONDITION error.
  244. //
  245. // Operations inside read-write transactions might return ABORTED. If
  246. // this occurs, the application should restart the transaction from
  247. // the beginning. See [Transaction][google.spanner.v1.Transaction] for more details.
  248. //
  249. // Larger result sets can be fetched in streaming fashion by calling
  250. // [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] instead.
  251. func (c *Client) ExecuteSql(ctx context.Context, req *spannerpb.ExecuteSqlRequest, opts ...gax.CallOption) (*spannerpb.ResultSet, error) {
  252. ctx = insertMetadata(ctx, c.xGoogMetadata)
  253. opts = append(c.CallOptions.ExecuteSql[0:len(c.CallOptions.ExecuteSql):len(c.CallOptions.ExecuteSql)], opts...)
  254. var resp *spannerpb.ResultSet
  255. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  256. var err error
  257. resp, err = c.client.ExecuteSql(ctx, req, settings.GRPC...)
  258. return err
  259. }, opts...)
  260. if err != nil {
  261. return nil, err
  262. }
  263. return resp, nil
  264. }
  265. // ExecuteStreamingSql like [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], except returns the result
  266. // set as a stream. Unlike [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], there
  267. // is no limit on the size of the returned result set. However, no
  268. // individual row in the result set can exceed 100 MiB, and no
  269. // column value can exceed 10 MiB.
  270. func (c *Client) ExecuteStreamingSql(ctx context.Context, req *spannerpb.ExecuteSqlRequest, opts ...gax.CallOption) (spannerpb.Spanner_ExecuteStreamingSqlClient, error) {
  271. ctx = insertMetadata(ctx, c.xGoogMetadata)
  272. opts = append(c.CallOptions.ExecuteStreamingSql[0:len(c.CallOptions.ExecuteStreamingSql):len(c.CallOptions.ExecuteStreamingSql)], opts...)
  273. var resp spannerpb.Spanner_ExecuteStreamingSqlClient
  274. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  275. var err error
  276. resp, err = c.client.ExecuteStreamingSql(ctx, req, settings.GRPC...)
  277. return err
  278. }, opts...)
  279. if err != nil {
  280. return nil, err
  281. }
  282. return resp, nil
  283. }
  284. // Read reads rows from the database using key lookups and scans, as a
  285. // simple key/value style alternative to
  286. // [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]. This method cannot be used to
  287. // return a result set larger than 10 MiB; if the read matches more
  288. // data than that, the read fails with a FAILED_PRECONDITION
  289. // error.
  290. //
  291. // Reads inside read-write transactions might return ABORTED. If
  292. // this occurs, the application should restart the transaction from
  293. // the beginning. See [Transaction][google.spanner.v1.Transaction] for more details.
  294. //
  295. // Larger result sets can be yielded in streaming fashion by calling
  296. // [StreamingRead][google.spanner.v1.Spanner.StreamingRead] instead.
  297. func (c *Client) Read(ctx context.Context, req *spannerpb.ReadRequest, opts ...gax.CallOption) (*spannerpb.ResultSet, error) {
  298. ctx = insertMetadata(ctx, c.xGoogMetadata)
  299. opts = append(c.CallOptions.Read[0:len(c.CallOptions.Read):len(c.CallOptions.Read)], opts...)
  300. var resp *spannerpb.ResultSet
  301. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  302. var err error
  303. resp, err = c.client.Read(ctx, req, settings.GRPC...)
  304. return err
  305. }, opts...)
  306. if err != nil {
  307. return nil, err
  308. }
  309. return resp, nil
  310. }
  311. // StreamingRead like [Read][google.spanner.v1.Spanner.Read], except returns the result set as a
  312. // stream. Unlike [Read][google.spanner.v1.Spanner.Read], there is no limit on the
  313. // size of the returned result set. However, no individual row in
  314. // the result set can exceed 100 MiB, and no column value can exceed
  315. // 10 MiB.
  316. func (c *Client) StreamingRead(ctx context.Context, req *spannerpb.ReadRequest, opts ...gax.CallOption) (spannerpb.Spanner_StreamingReadClient, error) {
  317. ctx = insertMetadata(ctx, c.xGoogMetadata)
  318. opts = append(c.CallOptions.StreamingRead[0:len(c.CallOptions.StreamingRead):len(c.CallOptions.StreamingRead)], opts...)
  319. var resp spannerpb.Spanner_StreamingReadClient
  320. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  321. var err error
  322. resp, err = c.client.StreamingRead(ctx, req, settings.GRPC...)
  323. return err
  324. }, opts...)
  325. if err != nil {
  326. return nil, err
  327. }
  328. return resp, nil
  329. }
  330. // BeginTransaction begins a new transaction. This step can often be skipped:
  331. // [Read][google.spanner.v1.Spanner.Read], [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
  332. // [Commit][google.spanner.v1.Spanner.Commit] can begin a new transaction as a
  333. // side-effect.
  334. func (c *Client) BeginTransaction(ctx context.Context, req *spannerpb.BeginTransactionRequest, opts ...gax.CallOption) (*spannerpb.Transaction, error) {
  335. ctx = insertMetadata(ctx, c.xGoogMetadata)
  336. opts = append(c.CallOptions.BeginTransaction[0:len(c.CallOptions.BeginTransaction):len(c.CallOptions.BeginTransaction)], opts...)
  337. var resp *spannerpb.Transaction
  338. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  339. var err error
  340. resp, err = c.client.BeginTransaction(ctx, req, settings.GRPC...)
  341. return err
  342. }, opts...)
  343. if err != nil {
  344. return nil, err
  345. }
  346. return resp, nil
  347. }
  348. // Commit commits a transaction. The request includes the mutations to be
  349. // applied to rows in the database.
  350. //
  351. // Commit might return an ABORTED error. This can occur at any time;
  352. // commonly, the cause is conflicts with concurrent
  353. // transactions. However, it can also happen for a variety of other
  354. // reasons. If Commit returns ABORTED, the caller should re-attempt
  355. // the transaction from the beginning, re-using the same session.
  356. func (c *Client) Commit(ctx context.Context, req *spannerpb.CommitRequest, opts ...gax.CallOption) (*spannerpb.CommitResponse, error) {
  357. ctx = insertMetadata(ctx, c.xGoogMetadata)
  358. opts = append(c.CallOptions.Commit[0:len(c.CallOptions.Commit):len(c.CallOptions.Commit)], opts...)
  359. var resp *spannerpb.CommitResponse
  360. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  361. var err error
  362. resp, err = c.client.Commit(ctx, req, settings.GRPC...)
  363. return err
  364. }, opts...)
  365. if err != nil {
  366. return nil, err
  367. }
  368. return resp, nil
  369. }
  370. // Rollback rolls back a transaction, releasing any locks it holds. It is a good
  371. // idea to call this for any transaction that includes one or more
  372. // [Read][google.spanner.v1.Spanner.Read] or [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] requests and
  373. // ultimately decides not to commit.
  374. //
  375. // Rollback returns OK if it successfully aborts the transaction, the
  376. // transaction was already aborted, or the transaction is not
  377. // found. Rollback never returns ABORTED.
  378. func (c *Client) Rollback(ctx context.Context, req *spannerpb.RollbackRequest, opts ...gax.CallOption) error {
  379. ctx = insertMetadata(ctx, c.xGoogMetadata)
  380. opts = append(c.CallOptions.Rollback[0:len(c.CallOptions.Rollback):len(c.CallOptions.Rollback)], opts...)
  381. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  382. var err error
  383. _, err = c.client.Rollback(ctx, req, settings.GRPC...)
  384. return err
  385. }, opts...)
  386. return err
  387. }
  388. // PartitionQuery creates a set of partition tokens that can be used to execute a query
  389. // operation in parallel. Each of the returned partition tokens can be used
  390. // by [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] to specify a subset
  391. // of the query result to read. The same session and read-only transaction
  392. // must be used by the PartitionQueryRequest used to create the
  393. // partition tokens and the ExecuteSqlRequests that use the partition tokens.
  394. //
  395. // Partition tokens become invalid when the session used to create them
  396. // is deleted, is idle for too long, begins a new transaction, or becomes too
  397. // old. When any of these happen, it is not possible to resume the query, and
  398. // the whole operation must be restarted from the beginning.
  399. func (c *Client) PartitionQuery(ctx context.Context, req *spannerpb.PartitionQueryRequest, opts ...gax.CallOption) (*spannerpb.PartitionResponse, error) {
  400. ctx = insertMetadata(ctx, c.xGoogMetadata)
  401. opts = append(c.CallOptions.PartitionQuery[0:len(c.CallOptions.PartitionQuery):len(c.CallOptions.PartitionQuery)], opts...)
  402. var resp *spannerpb.PartitionResponse
  403. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  404. var err error
  405. resp, err = c.client.PartitionQuery(ctx, req, settings.GRPC...)
  406. return err
  407. }, opts...)
  408. if err != nil {
  409. return nil, err
  410. }
  411. return resp, nil
  412. }
  413. // PartitionRead creates a set of partition tokens that can be used to execute a read
  414. // operation in parallel. Each of the returned partition tokens can be used
  415. // by [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to specify a subset of the read
  416. // result to read. The same session and read-only transaction must be used by
  417. // the PartitionReadRequest used to create the partition tokens and the
  418. // ReadRequests that use the partition tokens. There are no ordering
  419. // guarantees on rows returned among the returned partition tokens, or even
  420. // within each individual StreamingRead call issued with a partition_token.
  421. //
  422. // Partition tokens become invalid when the session used to create them
  423. // is deleted, is idle for too long, begins a new transaction, or becomes too
  424. // old. When any of these happen, it is not possible to resume the read, and
  425. // the whole operation must be restarted from the beginning.
  426. func (c *Client) PartitionRead(ctx context.Context, req *spannerpb.PartitionReadRequest, opts ...gax.CallOption) (*spannerpb.PartitionResponse, error) {
  427. ctx = insertMetadata(ctx, c.xGoogMetadata)
  428. opts = append(c.CallOptions.PartitionRead[0:len(c.CallOptions.PartitionRead):len(c.CallOptions.PartitionRead)], opts...)
  429. var resp *spannerpb.PartitionResponse
  430. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  431. var err error
  432. resp, err = c.client.PartitionRead(ctx, req, settings.GRPC...)
  433. return err
  434. }, opts...)
  435. if err != nil {
  436. return nil, err
  437. }
  438. return resp, nil
  439. }
  440. // SessionIterator manages a stream of *spannerpb.Session.
  441. type SessionIterator struct {
  442. items []*spannerpb.Session
  443. pageInfo *iterator.PageInfo
  444. nextFunc func() error
  445. // InternalFetch is for use by the Google Cloud Libraries only.
  446. // It is not part of the stable interface of this package.
  447. //
  448. // InternalFetch returns results from a single call to the underlying RPC.
  449. // The number of results is no greater than pageSize.
  450. // If there are no more results, nextPageToken is empty and err is nil.
  451. InternalFetch func(pageSize int, pageToken string) (results []*spannerpb.Session, nextPageToken string, err error)
  452. }
  453. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  454. func (it *SessionIterator) PageInfo() *iterator.PageInfo {
  455. return it.pageInfo
  456. }
  457. // Next returns the next result. Its second return value is iterator.Done if there are no more
  458. // results. Once Next returns Done, all subsequent calls will return Done.
  459. func (it *SessionIterator) Next() (*spannerpb.Session, error) {
  460. var item *spannerpb.Session
  461. if err := it.nextFunc(); err != nil {
  462. return item, err
  463. }
  464. item = it.items[0]
  465. it.items = it.items[1:]
  466. return item, nil
  467. }
  468. func (it *SessionIterator) bufLen() int {
  469. return len(it.items)
  470. }
  471. func (it *SessionIterator) takeBuf() interface{} {
  472. b := it.items
  473. it.items = nil
  474. return b
  475. }