http urls monitor.

interfaces.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // Copyright (c) 2015 The upper.io/db.v3/lib/sqlbuilder authors. All rights reserved.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be
  12. // included in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. package sqlbuilder
  22. import (
  23. "context"
  24. "database/sql"
  25. "fmt"
  26. )
  27. // SQLBuilder defines methods that can be used to build a SQL query with
  28. // chainable method calls.
  29. //
  30. // Queries are immutable, so every call to any method will return a new
  31. // pointer, if you want to build a query using variables you need to reassign
  32. // them, like this:
  33. //
  34. // a = builder.Select("name").From("foo") // "a" is created
  35. //
  36. // a.Where(...) // No effect, the value returned from Where is ignored.
  37. //
  38. // a = a.Where(...) // "a" is reassigned and points to a different address.
  39. //
  40. type SQLBuilder interface {
  41. // Select initializes and returns a Selector, it accepts column names as
  42. // parameters.
  43. //
  44. // The returned Selector does not initially point to any table, a call to
  45. // From() is required after Select() to complete a valid query.
  46. //
  47. // Example:
  48. //
  49. // q := sqlbuilder.Select("first_name", "last_name").From("people").Where(...)
  50. Select(columns ...interface{}) Selector
  51. // SelectFrom creates a Selector that selects all columns (like SELECT *)
  52. // from the given table.
  53. //
  54. // Example:
  55. //
  56. // q := sqlbuilder.SelectFrom("people").Where(...)
  57. SelectFrom(table ...interface{}) Selector
  58. // InsertInto prepares and returns an Inserter targeted at the given table.
  59. //
  60. // Example:
  61. //
  62. // q := sqlbuilder.InsertInto("books").Columns(...).Values(...)
  63. InsertInto(table string) Inserter
  64. // DeleteFrom prepares a Deleter targeted at the given table.
  65. //
  66. // Example:
  67. //
  68. // q := sqlbuilder.DeleteFrom("tasks").Where(...)
  69. DeleteFrom(table string) Deleter
  70. // Update prepares and returns an Updater targeted at the given table.
  71. //
  72. // Example:
  73. //
  74. // q := sqlbuilder.Update("profile").Set(...).Where(...)
  75. Update(table string) Updater
  76. // Exec executes a SQL query that does not return any rows, like sql.Exec.
  77. // Queries can be either strings or upper-db statements.
  78. //
  79. // Example:
  80. //
  81. // sqlbuilder.Exec(`INSERT INTO books (title) VALUES("La Ciudad y los Perros")`)
  82. Exec(query interface{}, args ...interface{}) (sql.Result, error)
  83. // ExecContext executes a SQL query that does not return any rows, like sql.ExecContext.
  84. // Queries can be either strings or upper-db statements.
  85. //
  86. // Example:
  87. //
  88. // sqlbuilder.ExecContext(ctx, `INSERT INTO books (title) VALUES(?)`, "La Ciudad y los Perros")
  89. ExecContext(ctx context.Context, query interface{}, args ...interface{}) (sql.Result, error)
  90. // Prepare creates a prepared statement for later queries or executions. The
  91. // caller must call the statement's Close method when the statement is no
  92. // longer needed.
  93. Prepare(query interface{}) (*sql.Stmt, error)
  94. // Prepare creates a prepared statement on the guiven context for later
  95. // queries or executions. The caller must call the statement's Close method
  96. // when the statement is no longer needed.
  97. PrepareContext(ctx context.Context, query interface{}) (*sql.Stmt, error)
  98. // Query executes a SQL query that returns rows, like sql.Query. Queries can
  99. // be either strings or upper-db statements.
  100. //
  101. // Example:
  102. //
  103. // sqlbuilder.Query(`SELECT * FROM people WHERE name = "Mateo"`)
  104. Query(query interface{}, args ...interface{}) (*sql.Rows, error)
  105. // QueryContext executes a SQL query that returns rows, like
  106. // sql.QueryContext. Queries can be either strings or upper-db statements.
  107. //
  108. // Example:
  109. //
  110. // sqlbuilder.QueryContext(ctx, `SELECT * FROM people WHERE name = ?`, "Mateo")
  111. QueryContext(ctx context.Context, query interface{}, args ...interface{}) (*sql.Rows, error)
  112. // QueryRow executes a SQL query that returns one row, like sql.QueryRow.
  113. // Queries can be either strings or upper-db statements.
  114. //
  115. // Example:
  116. //
  117. // sqlbuilder.QueryRow(`SELECT * FROM people WHERE name = "Haruki" AND last_name = "Murakami" LIMIT 1`)
  118. QueryRow(query interface{}, args ...interface{}) (*sql.Row, error)
  119. // QueryRowContext executes a SQL query that returns one row, like
  120. // sql.QueryRowContext. Queries can be either strings or upper-db statements.
  121. //
  122. // Example:
  123. //
  124. // sqlbuilder.QueryRowContext(ctx, `SELECT * FROM people WHERE name = "Haruki" AND last_name = "Murakami" LIMIT 1`)
  125. QueryRowContext(ctx context.Context, query interface{}, args ...interface{}) (*sql.Row, error)
  126. // Iterator executes a SQL query that returns rows and creates an Iterator
  127. // with it.
  128. //
  129. // Example:
  130. //
  131. // sqlbuilder.Iterator(`SELECT * FROM people WHERE name LIKE "M%"`)
  132. Iterator(query interface{}, args ...interface{}) Iterator
  133. // IteratorContext executes a SQL query that returns rows and creates an Iterator
  134. // with it.
  135. //
  136. // Example:
  137. //
  138. // sqlbuilder.IteratorContext(ctx, `SELECT * FROM people WHERE name LIKE "M%"`)
  139. IteratorContext(ctx context.Context, query interface{}, args ...interface{}) Iterator
  140. }
  141. // Selector represents a SELECT statement.
  142. type Selector interface {
  143. // Columns defines which columns to retrive.
  144. //
  145. // You should call From() after Columns() if you want to query data from an
  146. // specific table.
  147. //
  148. // s.Columns("name", "last_name").From(...)
  149. //
  150. // It is also possible to use an alias for the column, this could be handy if
  151. // you plan to use the alias later, use the "AS" keyword to denote an alias.
  152. //
  153. // s.Columns("name AS n")
  154. //
  155. // or the shortcut:
  156. //
  157. // s.Columns("name n")
  158. //
  159. // If you don't want the column to be escaped use the sqlbuilder.RawString
  160. // function.
  161. //
  162. // s.Columns(sqlbuilder.RawString("DATABASE_NAME()"))
  163. //
  164. // The above statement is equivalent to:
  165. //
  166. // s.Columns(sqlbuilder.Func("DATABASE_NAME"))
  167. Columns(columns ...interface{}) Selector
  168. // From represents a FROM clause and is tipically used after Columns().
  169. //
  170. // FROM defines from which table data is going to be retrieved
  171. //
  172. // s.Columns(...).From("people")
  173. //
  174. // It is also possible to use an alias for the table, this could be handy if
  175. // you plan to use the alias later:
  176. //
  177. // s.Columns(...).From("people AS p").Where("p.name = ?", ...)
  178. //
  179. // Or with the shortcut:
  180. //
  181. // s.Columns(...).From("people p").Where("p.name = ?", ...)
  182. From(tables ...interface{}) Selector
  183. // Distict represents a DISCTINCT clause
  184. //
  185. // DISCTINC is used to ask the database to return only values that are
  186. // different.
  187. Distinct(columns ...interface{}) Selector
  188. // As defines an alias for a table.
  189. As(string) Selector
  190. // Where specifies the conditions that columns must match in order to be
  191. // retrieved.
  192. //
  193. // Where accepts raw strings and fmt.Stringer to define conditions and
  194. // interface{} to specify parameters. Be careful not to embed any parameters
  195. // within the SQL part as that could lead to security problems. You can use
  196. // que question mark (?) as placeholder for parameters.
  197. //
  198. // s.Where("name = ?", "max")
  199. //
  200. // s.Where("name = ? AND last_name = ?", "Mary", "Doe")
  201. //
  202. // s.Where("last_name IS NULL")
  203. //
  204. // You can also use other types of parameters besides only strings, like:
  205. //
  206. // s.Where("online = ? AND last_logged <= ?", true, time.Now())
  207. //
  208. // and Where() will transform them into strings before feeding them to the
  209. // database.
  210. //
  211. // When an unknown type is provided, Where() will first try to match it with
  212. // the Marshaler interface, then with fmt.Stringer and finally, if the
  213. // argument does not satisfy any of those interfaces Where() will use
  214. // fmt.Sprintf("%v", arg) to transform the type into a string.
  215. //
  216. // Subsequent calls to Where() will overwrite previously set conditions, if
  217. // you want these new conditions to be appended use And() instead.
  218. Where(conds ...interface{}) Selector
  219. // And appends more constraints to the WHERE clause without overwriting
  220. // conditions that have been already set.
  221. And(conds ...interface{}) Selector
  222. // GroupBy represents a GROUP BY statement.
  223. //
  224. // GROUP BY defines which columns should be used to aggregate and group
  225. // results.
  226. //
  227. // s.GroupBy("country_id")
  228. //
  229. // GroupBy accepts more than one column:
  230. //
  231. // s.GroupBy("country_id", "city_id")
  232. GroupBy(columns ...interface{}) Selector
  233. // Having(...interface{}) Selector
  234. // OrderBy represents a ORDER BY statement.
  235. //
  236. // ORDER BY is used to define which columns are going to be used to sort
  237. // results.
  238. //
  239. // Use the column name to sort results in ascendent order.
  240. //
  241. // // "last_name" ASC
  242. // s.OrderBy("last_name")
  243. //
  244. // Prefix the column name with the minus sign (-) to sort results in
  245. // descendent order.
  246. //
  247. // // "last_name" DESC
  248. // s.OrderBy("-last_name")
  249. //
  250. // If you would rather be very explicit, you can also use ASC and DESC.
  251. //
  252. // s.OrderBy("last_name ASC")
  253. //
  254. // s.OrderBy("last_name DESC", "name ASC")
  255. OrderBy(columns ...interface{}) Selector
  256. // Join represents a JOIN statement.
  257. //
  258. // JOIN statements are used to define external tables that the user wants to
  259. // include as part of the result.
  260. //
  261. // You can use the On() method after Join() to define the conditions of the
  262. // join.
  263. //
  264. // s.Join("author").On("author.id = book.author_id")
  265. //
  266. // If you don't specify conditions for the join, a NATURAL JOIN will be used.
  267. //
  268. // On() accepts the same arguments as Where()
  269. //
  270. // You can also use Using() after Join().
  271. //
  272. // s.Join("employee").Using("department_id")
  273. Join(table ...interface{}) Selector
  274. // FullJoin is like Join() but with FULL JOIN.
  275. FullJoin(...interface{}) Selector
  276. // CrossJoin is like Join() but with CROSS JOIN.
  277. CrossJoin(...interface{}) Selector
  278. // RightJoin is like Join() but with RIGHT JOIN.
  279. RightJoin(...interface{}) Selector
  280. // LeftJoin is like Join() but with LEFT JOIN.
  281. LeftJoin(...interface{}) Selector
  282. // Using represents the USING clause.
  283. //
  284. // USING is used to specifiy columns to join results.
  285. //
  286. // s.LeftJoin(...).Using("country_id")
  287. Using(...interface{}) Selector
  288. // On represents the ON clause.
  289. //
  290. // ON is used to define conditions on a join.
  291. //
  292. // s.Join(...).On("b.author_id = a.id")
  293. On(...interface{}) Selector
  294. // Limit represents the LIMIT parameter.
  295. //
  296. // LIMIT defines the maximum number of rows to return from the table. A
  297. // negative limit cancels any previous limit settings.
  298. //
  299. // s.Limit(42)
  300. Limit(int) Selector
  301. // Offset represents the OFFSET parameter.
  302. //
  303. // OFFSET defines how many results are going to be skipped before starting to
  304. // return results. A negative offset cancels any previous offset settings.
  305. //
  306. // s.Offset(56)
  307. Offset(int) Selector
  308. // Amend lets you alter the query's text just before sending it to the
  309. // database server.
  310. Amend(func(queryIn string) (queryOut string)) Selector
  311. // Paginate returns a paginator that can display a paginated lists of items.
  312. // Paginators ignore previous Offset and Limit settings. Page numbering
  313. // starts at 1.
  314. Paginate(uint) Paginator
  315. // Iterator provides methods to iterate over the results returned by the
  316. // Selector.
  317. Iterator() Iterator
  318. // IteratorContext provides methods to iterate over the results returned by
  319. // the Selector.
  320. IteratorContext(ctx context.Context) Iterator
  321. // Preparer provides methods for creating prepared statements.
  322. Preparer
  323. // Getter provides methods to compile and execute a query that returns
  324. // results.
  325. Getter
  326. // ResultMapper provides methods to retrieve and map results.
  327. ResultMapper
  328. // fmt.Stringer provides `String() string`, you can use `String()` to compile
  329. // the `Selector` into a string.
  330. fmt.Stringer
  331. // Arguments returns the arguments that are prepared for this query.
  332. Arguments() []interface{}
  333. }
  334. // Inserter represents an INSERT statement.
  335. type Inserter interface {
  336. // Columns represents the COLUMNS clause.
  337. //
  338. // COLUMNS defines the columns that we are going to provide values for.
  339. //
  340. // i.Columns("name", "last_name").Values(...)
  341. Columns(...string) Inserter
  342. // Values represents the VALUES clause.
  343. //
  344. // VALUES defines the values of the columns.
  345. //
  346. // i.Columns(...).Values("María", "Méndez")
  347. //
  348. // i.Values(map[string][string]{"name": "María"})
  349. Values(...interface{}) Inserter
  350. // Arguments returns the arguments that are prepared for this query.
  351. Arguments() []interface{}
  352. // Returning represents a RETURNING clause.
  353. //
  354. // RETURNING specifies which columns should be returned after INSERT.
  355. //
  356. // RETURNING may not be supported by all SQL databases.
  357. Returning(columns ...string) Inserter
  358. // Iterator provides methods to iterate over the results returned by the
  359. // Inserter. This is only possible when using Returning().
  360. Iterator() Iterator
  361. // IteratorContext provides methods to iterate over the results returned by
  362. // the Inserter. This is only possible when using Returning().
  363. IteratorContext(ctx context.Context) Iterator
  364. // Amend lets you alter the query's text just before sending it to the
  365. // database server.
  366. Amend(func(queryIn string) (queryOut string)) Inserter
  367. // Batch provies a BatchInserter that can be used to insert many elements at
  368. // once by issuing several calls to Values(). It accepts a size parameter
  369. // which defines the batch size. If size is < 1, the batch size is set to 1.
  370. Batch(size int) *BatchInserter
  371. // Execer provides the Exec method.
  372. Execer
  373. // Preparer provides methods for creating prepared statements.
  374. Preparer
  375. // Getter provides methods to return query results from INSERT statements
  376. // that support such feature (e.g.: queries with Returning).
  377. Getter
  378. // fmt.Stringer provides `String() string`, you can use `String()` to compile
  379. // the `Inserter` into a string.
  380. fmt.Stringer
  381. }
  382. // Deleter represents a DELETE statement.
  383. type Deleter interface {
  384. // Where represents the WHERE clause.
  385. //
  386. // See Selector.Where for documentation and usage examples.
  387. Where(...interface{}) Deleter
  388. // And appends more constraints to the WHERE clause without overwriting
  389. // conditions that have been already set.
  390. And(conds ...interface{}) Deleter
  391. // Limit represents the LIMIT clause.
  392. //
  393. // See Selector.Limit for documentation and usage examples.
  394. Limit(int) Deleter
  395. // Amend lets you alter the query's text just before sending it to the
  396. // database server.
  397. Amend(func(queryIn string) (queryOut string)) Deleter
  398. // Preparer provides methods for creating prepared statements.
  399. Preparer
  400. // Execer provides the Exec method.
  401. Execer
  402. // fmt.Stringer provides `String() string`, you can use `String()` to compile
  403. // the `Inserter` into a string.
  404. fmt.Stringer
  405. // Arguments returns the arguments that are prepared for this query.
  406. Arguments() []interface{}
  407. }
  408. // Updater represents an UPDATE statement.
  409. type Updater interface {
  410. // Set represents the SET clause.
  411. Set(...interface{}) Updater
  412. // Where represents the WHERE clause.
  413. //
  414. // See Selector.Where for documentation and usage examples.
  415. Where(...interface{}) Updater
  416. // And appends more constraints to the WHERE clause without overwriting
  417. // conditions that have been already set.
  418. And(conds ...interface{}) Updater
  419. // Limit represents the LIMIT parameter.
  420. //
  421. // See Selector.Limit for documentation and usage examples.
  422. Limit(int) Updater
  423. // Preparer provides methods for creating prepared statements.
  424. Preparer
  425. // Execer provides the Exec method.
  426. Execer
  427. // fmt.Stringer provides `String() string`, you can use `String()` to compile
  428. // the `Inserter` into a string.
  429. fmt.Stringer
  430. // Arguments returns the arguments that are prepared for this query.
  431. Arguments() []interface{}
  432. // Amend lets you alter the query's text just before sending it to the
  433. // database server.
  434. Amend(func(queryIn string) (queryOut string)) Updater
  435. }
  436. // Execer provides methods for executing statements that do not return results.
  437. type Execer interface {
  438. // Exec executes a statement and returns sql.Result.
  439. Exec() (sql.Result, error)
  440. // ExecContext executes a statement and returns sql.Result.
  441. ExecContext(context.Context) (sql.Result, error)
  442. }
  443. // Preparer provides the Prepare and PrepareContext methods for creating
  444. // prepared statements.
  445. type Preparer interface {
  446. // Prepare creates a prepared statement.
  447. Prepare() (*sql.Stmt, error)
  448. // PrepareContext creates a prepared statement.
  449. PrepareContext(context.Context) (*sql.Stmt, error)
  450. }
  451. // Getter provides methods for executing statements that return results.
  452. type Getter interface {
  453. // Query returns *sql.Rows.
  454. Query() (*sql.Rows, error)
  455. // QueryContext returns *sql.Rows.
  456. QueryContext(context.Context) (*sql.Rows, error)
  457. // QueryRow returns only one row.
  458. QueryRow() (*sql.Row, error)
  459. // QueryRowContext returns only one row.
  460. QueryRowContext(ctx context.Context) (*sql.Row, error)
  461. }
  462. // Paginator provides tools for splitting the results of a query into chunks
  463. // containing a fixed number of items.
  464. type Paginator interface {
  465. // Page sets the page number.
  466. Page(uint) Paginator
  467. // Cursor defines the column that is going to be taken as basis for
  468. // cursor-based pagination.
  469. //
  470. // Example:
  471. //
  472. // a = q.Paginate(10).Cursor("id")
  473. // b = q.Paginate(12).Cursor("-id")
  474. //
  475. // You can set "" as cursorColumn to disable cursors.
  476. Cursor(cursorColumn string) Paginator
  477. // NextPage returns the next page according to the cursor. It expects a
  478. // cursorValue, which is the value the cursor column has on the last item of
  479. // the current result set (lower bound).
  480. //
  481. // Example:
  482. //
  483. // p = q.NextPage(items[len(items)-1].ID)
  484. NextPage(cursorValue interface{}) Paginator
  485. // PrevPage returns the previous page according to the cursor. It expects a
  486. // cursorValue, which is the value the cursor column has on the fist item of
  487. // the current result set (upper bound).
  488. //
  489. // Example:
  490. //
  491. // p = q.PrevPage(items[0].ID)
  492. PrevPage(cursorValue interface{}) Paginator
  493. // TotalPages returns the total number of pages in the query.
  494. TotalPages() (uint, error)
  495. // TotalEntries returns the total number of entries in the query.
  496. TotalEntries() (uint64, error)
  497. // Preparer provides methods for creating prepared statements.
  498. Preparer
  499. // Getter provides methods to compile and execute a query that returns
  500. // results.
  501. Getter
  502. // Iterator provides methods to iterate over the results returned by the
  503. // Selector.
  504. Iterator() Iterator
  505. // IteratorContext provides methods to iterate over the results returned by
  506. // the Selector.
  507. IteratorContext(ctx context.Context) Iterator
  508. // ResultMapper provides methods to retrieve and map results.
  509. ResultMapper
  510. // fmt.Stringer provides `String() string`, you can use `String()` to compile
  511. // the `Selector` into a string.
  512. fmt.Stringer
  513. // Arguments returns the arguments that are prepared for this query.
  514. Arguments() []interface{}
  515. }
  516. // ResultMapper defined methods for a result mapper.
  517. type ResultMapper interface {
  518. // All dumps all the results into the given slice, All() expects a pointer to
  519. // slice of maps or structs.
  520. //
  521. // The behaviour of One() extends to each one of the results.
  522. All(destSlice interface{}) error
  523. // One maps the row that is in the current query cursor into the
  524. // given interface, which can be a pointer to either a map or a
  525. // struct.
  526. //
  527. // If dest is a pointer to map, each one of the columns will create a new map
  528. // key and the values of the result will be set as values for the keys.
  529. //
  530. // Depending on the type of map key and value, the results columns and values
  531. // may need to be transformed.
  532. //
  533. // If dest if a pointer to struct, each one of the fields will be tested for
  534. // a `db` tag which defines the column mapping. The value of the result will
  535. // be set as the value of the field.
  536. One(dest interface{}) error
  537. }
  538. // Iterator provides methods for iterating over query results.
  539. type Iterator interface {
  540. // ResultMapper provides methods to retrieve and map results.
  541. ResultMapper
  542. // Scan dumps the current result into the given pointer variable pointers.
  543. Scan(dest ...interface{}) error
  544. // NextScan advances the iterator and performs Scan.
  545. NextScan(dest ...interface{}) error
  546. // ScanOne advances the iterator, performs Scan and closes the iterator.
  547. ScanOne(dest ...interface{}) error
  548. // Next dumps the current element into the given destination, which could be
  549. // a pointer to either a map or a struct.
  550. Next(dest ...interface{}) bool
  551. // Err returns the last error produced by the cursor.
  552. Err() error
  553. // Close closes the iterator and frees up the cursor.
  554. Close() error
  555. }