lisette-stdlib 0.1.16

Little language inspired by Rust that compiles to Go
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
// Generated by Lisette bindgen
// Source: database/sql (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.14

import "go:context"
import "go:database/sql/driver"
import "go:reflect"
import "go:time"

pub enum IsolationLevel: int {
  LevelDefault = 0,
  LevelLinearizable = 7,
  LevelReadCommitted = 2,
  LevelReadUncommitted = 1,
  LevelRepeatableRead = 4,
  LevelSerializable = 6,
  LevelSnapshot = 5,
  LevelWriteCommitted = 3,
}

pub const LevelDefault: IsolationLevel = 0

pub const LevelLinearizable: IsolationLevel = 7

pub const LevelReadCommitted: IsolationLevel = 2

pub const LevelReadUncommitted: IsolationLevel = 1

pub const LevelRepeatableRead: IsolationLevel = 4

pub const LevelSerializable: IsolationLevel = 6

pub const LevelSnapshot: IsolationLevel = 5

pub const LevelWriteCommitted: IsolationLevel = 3

/// Drivers returns a sorted list of the names of the registered drivers.
pub fn Drivers() -> Slice<string>

pub fn Named(name: string, value: Unknown) -> NamedArg

pub fn Open(driverName: string, dataSourceName: string) -> Result<Ref<DB>, error>

pub fn OpenDB(c: driver.Connector) -> Ref<DB>

/// Register makes a database driver available by the provided name.
/// If Register is called twice with the same name or if driver is nil,
/// it panics.
pub fn Register(name: string, driver: driver.Driver)

/// ColumnType contains the name and type of a column.
pub type ColumnType

/// Conn represents a single database connection rather than a pool of database
/// connections. Prefer running queries from [DB] unless there is a specific
/// need for a continuous single database connection.
/// 
/// A Conn must call [Conn.Close] to return the connection to the database pool
/// and may do so concurrently with a running query.
/// 
/// After a call to [Conn.Close], all operations on the
/// connection fail with [ErrConnDone].
pub type Conn

/// DB is a database handle representing a pool of zero or more
/// underlying connections. It's safe for concurrent use by multiple
/// goroutines.
/// 
/// The sql package creates and frees connections automatically; it
/// also maintains a free pool of idle connections. If the database has
/// a concept of per-connection state, such state can be reliably observed
/// within a transaction ([Tx]) or connection ([Conn]). Once [DB.Begin] is called, the
/// returned [Tx] is bound to a single connection. Once [Tx.Commit] or
/// [Tx.Rollback] is called on the transaction, that transaction's
/// connection is returned to [DB]'s idle connection pool. The pool size
/// can be controlled with [DB.SetMaxIdleConns].
pub type DB

/// DBStats contains database statistics.
pub struct DBStats {
  pub MaxOpenConnections: int,
  pub OpenConnections: int,
  pub InUse: int,
  pub Idle: int,
  pub WaitCount: int64,
  pub WaitDuration: time.Duration,
  pub MaxIdleClosed: int64,
  pub MaxIdleTimeClosed: int64,
  pub MaxLifetimeClosed: int64,
}

/// A NamedArg is a named argument. NamedArg values may be used as
/// arguments to [DB.Query] or [DB.Exec] and bind to the corresponding named
/// parameter in the SQL statement.
/// 
/// For a more concise way to create NamedArg values, see
/// the [Named] function.
pub struct NamedArg {
  pub Name: string,
  pub Value: Unknown,
}

/// Null represents a value that may be null.
/// Null implements the [Scanner] interface so
/// it can be used as a scan destination:
/// 
/// 	var s Null[string]
/// 	err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&s)
/// 	...
/// 	if s.Valid {
/// 	   // use s.V
/// 	} else {
/// 	   // NULL value
/// 	}
/// 
/// T should be one of the types accepted by [driver.Value].
pub struct Null<T> {
  pub V: T,
  pub Valid: bool,
}

/// NullBool represents a bool that may be null.
/// NullBool implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullBool {
  pub Bool: bool,
  pub Valid: bool,
}

/// NullByte represents a byte that may be null.
/// NullByte implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullByte {
  pub Byte: uint8,
  pub Valid: bool,
}

/// NullFloat64 represents a float64 that may be null.
/// NullFloat64 implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullFloat64 {
  pub Float64: float64,
  pub Valid: bool,
}

/// NullInt16 represents an int16 that may be null.
/// NullInt16 implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullInt16 {
  pub Int16: int16,
  pub Valid: bool,
}

/// NullInt32 represents an int32 that may be null.
/// NullInt32 implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullInt32 {
  pub Int32: int32,
  pub Valid: bool,
}

/// NullInt64 represents an int64 that may be null.
/// NullInt64 implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullInt64 {
  pub Int64: int64,
  pub Valid: bool,
}

/// NullString represents a string that may be null.
/// NullString implements the [Scanner] interface so
/// it can be used as a scan destination:
/// 
/// 	var s NullString
/// 	err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&s)
/// 	...
/// 	if s.Valid {
/// 	   // use s.String
/// 	} else {
/// 	   // NULL value
/// 	}
pub struct NullString {
  pub String: string,
  pub Valid: bool,
}

/// NullTime represents a [time.Time] that may be null.
/// NullTime implements the [Scanner] interface so
/// it can be used as a scan destination, similar to [NullString].
pub struct NullTime {
  pub Time: time.Time,
  pub Valid: bool,
}

/// Out may be used to retrieve OUTPUT value parameters from stored procedures.
/// 
/// Not all drivers and databases support OUTPUT value parameters.
/// 
/// Example usage:
/// 
/// 	var outArg string
/// 	_, err := db.ExecContext(ctx, "ProcName", sql.Named("Arg1", sql.Out{Dest: &outArg}))
pub struct Out {
  pub Dest: Unknown,
  pub In: bool,
}

/// RawBytes is a byte slice that holds a reference to memory owned by
/// the database itself. After a [Rows.Scan] into a RawBytes, the slice is only
/// valid until the next call to [Rows.Next], [Rows.Scan], or [Rows.Close].
pub struct RawBytes(Slice<uint8>)

/// A Result summarizes an executed SQL command.
pub interface Result {
  fn LastInsertId() -> Result<int64, error>
  fn RowsAffected() -> Result<int64, error>
}

/// Row is the result of calling [DB.QueryRow] to select a single row.
pub type Row

/// Rows is the result of a query. Its cursor starts before the first row
/// of the result set. Use [Rows.Next] to advance from row to row.
pub type Rows

/// Scanner is an interface used by [Rows.Scan].
pub interface Scanner {
  fn Scan(src: Unknown) -> Result<(), error>
}

/// Stmt is a prepared statement.
/// A Stmt is safe for concurrent use by multiple goroutines.
/// 
/// If a Stmt is prepared on a [Tx] or [Conn], it will be bound to a single
/// underlying connection forever. If the [Tx] or [Conn] closes, the Stmt will
/// become unusable and all operations will return an error.
/// If a Stmt is prepared on a [DB], it will remain usable for the lifetime of the
/// [DB]. When the Stmt needs to execute on a new underlying connection, it will
/// prepare itself on the new connection automatically.
pub type Stmt

/// Tx is an in-progress database transaction.
/// 
/// A transaction must end with a call to [Tx.Commit] or [Tx.Rollback].
/// 
/// After a call to [Tx.Commit] or [Tx.Rollback], all operations on the
/// transaction fail with [ErrTxDone].
/// 
/// The statements prepared for a transaction by calling
/// the transaction's [Tx.Prepare] or [Tx.Stmt] methods are closed
/// by the call to [Tx.Commit] or [Tx.Rollback].
pub type Tx

/// TxOptions holds the transaction options to be used in [DB.BeginTx].
pub struct TxOptions {
  pub Isolation: IsolationLevel,
  pub ReadOnly: bool,
}

/// ErrConnDone is returned by any operation that is performed on a connection
/// that has already been returned to the connection pool.
pub var ErrConnDone: error

/// ErrNoRows is returned by [Row.Scan] when [DB.QueryRow] doesn't return a
/// row. In such a case, QueryRow returns a placeholder [*Row] value that
/// defers this error until a Scan.
pub var ErrNoRows: error

/// ErrTxDone is returned by any operation that is performed on a transaction
/// that has already been committed or rolled back.
pub var ErrTxDone: error

impl ColumnType {
  /// DatabaseTypeName returns the database system name of the column type. If an empty
  /// string is returned, then the driver type name is not supported.
  /// Consult your driver documentation for a list of driver data types. [ColumnType.Length] specifiers
  /// are not included.
  /// Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL",
  /// "INT", and "BIGINT".
  fn DatabaseTypeName(self: Ref<ColumnType>) -> string

  /// DecimalSize returns the scale and precision of a decimal type.
  /// If not applicable or if not supported ok is false.
  fn DecimalSize(self: Ref<ColumnType>) -> Option<(int64, int64)>

  /// Length returns the column type length for variable length column types such
  /// as text and binary field types. If the type length is unbounded the value will
  /// be [math.MaxInt64] (any database limits will still apply).
  /// If the column type is not variable length, such as an int, or if not supported
  /// by the driver ok is false.
  fn Length(self: Ref<ColumnType>) -> Option<int64>

  /// Name returns the name or alias of the column.
  fn Name(self: Ref<ColumnType>) -> string

  /// Nullable reports whether the column may be null.
  /// If a driver does not support this property ok will be false.
  fn Nullable(self: Ref<ColumnType>) -> Option<bool>

  /// ScanType returns a Go type suitable for scanning into using [Rows.Scan].
  /// If a driver does not support this property ScanType will return
  /// the type of an empty interface.
  fn ScanType(self: Ref<ColumnType>) -> Option<reflect.Type>
}

impl Conn {
  /// BeginTx starts a transaction.
  /// 
  /// The provided context is used until the transaction is committed or rolled back.
  /// If the context is canceled, the sql package will roll back
  /// the transaction. [Tx.Commit] will return an error if the context provided to
  /// BeginTx is canceled.
  /// 
  /// The provided [TxOptions] is optional and may be nil if defaults should be used.
  /// If a non-default isolation level is used that the driver doesn't support,
  /// an error will be returned.
  fn BeginTx(self: Ref<Conn>, ctx: context.Context, opts: Ref<TxOptions>) -> Result<Ref<Tx>, error>

  /// Close returns the connection to the connection pool.
  /// All operations after a Close will return with [ErrConnDone].
  /// Close is safe to call concurrently with other operations and will
  /// block until all other operations finish. It may be useful to first
  /// cancel any used context and then call close directly after.
  #[allow(unused_result)]
  fn Close(self: Ref<Conn>) -> Result<(), error>

  /// ExecContext executes a query without returning any rows.
  /// The args are for any placeholder parameters in the query.
  fn ExecContext(
    self: Ref<Conn>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Result<Result, error>

  /// PingContext verifies the connection to the database is still alive.
  fn PingContext(self: Ref<Conn>, ctx: context.Context) -> Result<(), error>

  /// PrepareContext creates a prepared statement for later queries or executions.
  /// Multiple queries or executions may be run concurrently from the
  /// returned statement.
  /// The caller must call the statement's [*Stmt.Close] method
  /// when the statement is no longer needed.
  /// 
  /// The provided context is used for the preparation of the statement, not for the
  /// execution of the statement.
  fn PrepareContext(self: Ref<Conn>, ctx: context.Context, query: string) -> Result<Ref<Stmt>, error>

  /// QueryContext executes a query that returns rows, typically a SELECT.
  /// The args are for any placeholder parameters in the query.
  fn QueryContext(
    self: Ref<Conn>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Result<Ref<Rows>, error>

  /// QueryRowContext executes a query that is expected to return at most one row.
  /// QueryRowContext always returns a non-nil value. Errors are deferred until
  /// the [*Row.Scan] method is called.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, the [*Row.Scan] scans the first selected row and discards
  /// the rest.
  fn QueryRowContext(
    self: Ref<Conn>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Ref<Row>

  /// Raw executes f exposing the underlying driver connection for the
  /// duration of f. The driverConn must not be used outside of f.
  /// 
  /// Once f returns and err is not [driver.ErrBadConn], the [Conn] will continue to be usable
  /// until [Conn.Close] is called.
  fn Raw(self: Ref<Conn>, f: fn(Unknown) -> Result<(), error>) -> Result<(), error>
}

impl DB {
  /// Begin starts a transaction. The default isolation level is dependent on
  /// the driver.
  /// 
  /// Begin uses [context.Background] internally; to specify the context, use
  /// [DB.BeginTx].
  fn Begin(self: Ref<DB>) -> Result<Ref<Tx>, error>

  /// BeginTx starts a transaction.
  /// 
  /// The provided context is used until the transaction is committed or rolled back.
  /// If the context is canceled, the sql package will roll back
  /// the transaction. [Tx.Commit] will return an error if the context provided to
  /// BeginTx is canceled.
  /// 
  /// The provided [TxOptions] is optional and may be nil if defaults should be used.
  /// If a non-default isolation level is used that the driver doesn't support,
  /// an error will be returned.
  fn BeginTx(self: Ref<DB>, ctx: context.Context, opts: Ref<TxOptions>) -> Result<Ref<Tx>, error>

  /// Close closes the database and prevents new queries from starting.
  /// Close then waits for all queries that have started processing on the server
  /// to finish.
  /// 
  /// It is rare to Close a [DB], as the [DB] handle is meant to be
  /// long-lived and shared between many goroutines.
  #[allow(unused_result)]
  fn Close(self: Ref<DB>) -> Result<(), error>

  /// Conn returns a single connection by either opening a new connection
  /// or returning an existing connection from the connection pool. Conn will
  /// block until either a connection is returned or ctx is canceled.
  /// Queries run on the same Conn will be run in the same database session.
  /// 
  /// Every Conn must be returned to the database pool after use by
  /// calling [Conn.Close].
  fn Conn(self: Ref<DB>, ctx: context.Context) -> Result<Ref<Conn>, error>

  /// Driver returns the database's underlying driver.
  fn Driver(self: Ref<DB>) -> driver.Driver

  /// Exec executes a query without returning any rows.
  /// The args are for any placeholder parameters in the query.
  /// 
  /// Exec uses [context.Background] internally; to specify the context, use
  /// [DB.ExecContext].
  fn Exec(self: Ref<DB>, query: string, args: VarArgs<Unknown>) -> Result<Result, error>

  /// ExecContext executes a query without returning any rows.
  /// The args are for any placeholder parameters in the query.
  fn ExecContext(
    self: Ref<DB>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Result<Result, error>

  /// Ping verifies a connection to the database is still alive,
  /// establishing a connection if necessary.
  /// 
  /// Ping uses [context.Background] internally; to specify the context, use
  /// [DB.PingContext].
  fn Ping(self: Ref<DB>) -> Result<(), error>

  /// PingContext verifies a connection to the database is still alive,
  /// establishing a connection if necessary.
  fn PingContext(self: Ref<DB>, ctx: context.Context) -> Result<(), error>

  /// Prepare creates a prepared statement for later queries or executions.
  /// Multiple queries or executions may be run concurrently from the
  /// returned statement.
  /// The caller must call the statement's [*Stmt.Close] method
  /// when the statement is no longer needed.
  /// 
  /// Prepare uses [context.Background] internally; to specify the context, use
  /// [DB.PrepareContext].
  fn Prepare(self: Ref<DB>, query: string) -> Result<Ref<Stmt>, error>

  /// PrepareContext creates a prepared statement for later queries or executions.
  /// Multiple queries or executions may be run concurrently from the
  /// returned statement.
  /// The caller must call the statement's [*Stmt.Close] method
  /// when the statement is no longer needed.
  /// 
  /// The provided context is used for the preparation of the statement, not for the
  /// execution of the statement.
  fn PrepareContext(self: Ref<DB>, ctx: context.Context, query: string) -> Result<Ref<Stmt>, error>

  /// Query executes a query that returns rows, typically a SELECT.
  /// The args are for any placeholder parameters in the query.
  /// 
  /// Query uses [context.Background] internally; to specify the context, use
  /// [DB.QueryContext].
  fn Query(self: Ref<DB>, query: string, args: VarArgs<Unknown>) -> Result<Ref<Rows>, error>

  /// QueryContext executes a query that returns rows, typically a SELECT.
  /// The args are for any placeholder parameters in the query.
  fn QueryContext(
    self: Ref<DB>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Result<Ref<Rows>, error>

  /// QueryRow executes a query that is expected to return at most one row.
  /// QueryRow always returns a non-nil value. Errors are deferred until
  /// [Row]'s Scan method is called.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, [*Row.Scan] scans the first selected row and discards
  /// the rest.
  /// 
  /// QueryRow uses [context.Background] internally; to specify the context, use
  /// [DB.QueryRowContext].
  fn QueryRow(self: Ref<DB>, query: string, args: VarArgs<Unknown>) -> Ref<Row>

  /// QueryRowContext executes a query that is expected to return at most one row.
  /// QueryRowContext always returns a non-nil value. Errors are deferred until
  /// [Row]'s Scan method is called.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, [*Row.Scan] scans the first selected row and discards
  /// the rest.
  fn QueryRowContext(
    self: Ref<DB>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Ref<Row>

  /// SetConnMaxIdleTime sets the maximum amount of time a connection may be idle.
  /// 
  /// Expired connections may be closed lazily before reuse.
  /// 
  /// If d <= 0, connections are not closed due to a connection's idle time.
  fn SetConnMaxIdleTime(self: Ref<DB>, d: time.Duration)

  /// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
  /// 
  /// Expired connections may be closed lazily before reuse.
  /// 
  /// If d <= 0, connections are not closed due to a connection's age.
  fn SetConnMaxLifetime(self: Ref<DB>, d: time.Duration)

  /// SetMaxIdleConns sets the maximum number of connections in the idle
  /// connection pool.
  /// 
  /// If MaxOpenConns is greater than 0 but less than the new MaxIdleConns,
  /// then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.
  /// 
  /// If n <= 0, no idle connections are retained.
  /// 
  /// The default max idle connections is currently 2. This may change in
  /// a future release.
  fn SetMaxIdleConns(self: Ref<DB>, n: int)

  /// SetMaxOpenConns sets the maximum number of open connections to the database.
  /// 
  /// If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than
  /// MaxIdleConns, then MaxIdleConns will be reduced to match the new
  /// MaxOpenConns limit.
  /// 
  /// If n <= 0, then there is no limit on the number of open connections.
  /// The default is 0 (unlimited).
  fn SetMaxOpenConns(self: Ref<DB>, n: int)

  /// Stats returns database statistics.
  fn Stats(self: Ref<DB>) -> DBStats
}

impl IsolationLevel {
  /// String returns the name of the transaction isolation level.
  fn String(self) -> string
}

impl<T> Null<T> {
  fn Scan(self: Ref<Null<T>>, value: Unknown) -> Result<(), error>

  fn Value(self) -> Result<driver.Value, error>
}

impl NullBool {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullBool>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullByte {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullByte>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullFloat64 {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullFloat64>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullInt16 {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullInt16>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullInt32 {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullInt32>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullInt64 {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullInt64>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullString {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullString>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl NullTime {
  /// Scan implements the [Scanner] interface.
  fn Scan(self: Ref<NullTime>, value: Unknown) -> Result<(), error>

  /// Value implements the [driver.Valuer] interface.
  fn Value(self) -> Result<driver.Value, error>
}

impl Row {
  /// Err provides a way for wrapping packages to check for
  /// query errors without calling [Row.Scan].
  /// Err returns the error, if any, that was encountered while running the query.
  /// If this error is not nil, this error will also be returned from [Row.Scan].
  fn Err(self: Ref<Row>) -> Option<error>

  /// Scan copies the columns from the matched row into the values
  /// pointed at by dest. See the documentation on [Rows.Scan] for details.
  /// If more than one row matches the query,
  /// Scan uses the first row and discards the rest. If no row matches
  /// the query, Scan returns [ErrNoRows].
  fn Scan(self: Ref<Row>, dest: VarArgs<Unknown>) -> Result<(), error>
}

impl Rows {
  /// Close closes the [Rows], preventing further enumeration. If [Rows.Next] is called
  /// and returns false and there are no further result sets,
  /// the [Rows] are closed automatically and it will suffice to check the
  /// result of [Rows.Err]. Close is idempotent and does not affect the result of [Rows.Err].
  #[allow(unused_result)]
  fn Close(self: Ref<Rows>) -> Result<(), error>

  /// ColumnTypes returns column information such as column type, length,
  /// and nullable. Some information may not be available from some drivers.
  fn ColumnTypes(self: Ref<Rows>) -> Result<Slice<Ref<ColumnType>>, error>

  /// Columns returns the column names.
  /// Columns returns an error if the rows are closed.
  fn Columns(self: Ref<Rows>) -> Result<Slice<string>, error>

  /// Err returns the error, if any, that was encountered during iteration.
  /// Err may be called after an explicit or implicit [Rows.Close].
  fn Err(self: Ref<Rows>) -> Option<error>

  /// Next prepares the next result row for reading with the [Rows.Scan] method. It
  /// returns true on success, or false if there is no next result row or an error
  /// happened while preparing it. [Rows.Err] should be consulted to distinguish between
  /// the two cases.
  /// 
  /// Every call to [Rows.Scan], even the first one, must be preceded by a call to [Rows.Next].
  fn Next(self: Ref<Rows>) -> bool

  /// NextResultSet prepares the next result set for reading. It reports whether
  /// there is further result sets, or false if there is no further result set
  /// or if there is an error advancing to it. The [Rows.Err] method should be consulted
  /// to distinguish between the two cases.
  /// 
  /// After calling NextResultSet, the [Rows.Next] method should always be called before
  /// scanning. If there are further result sets they may not have rows in the result
  /// set.
  fn NextResultSet(self: Ref<Rows>) -> bool

  /// Scan copies the columns in the current row into the values pointed
  /// at by dest. The number of values in dest must be the same as the
  /// number of columns in [Rows].
  /// 
  /// Scan converts columns read from the database into the following
  /// common Go types and special types provided by the sql package:
  /// 
  /// 	*string
  /// 	*[]byte
  /// 	*int, *int8, *int16, *int32, *int64
  /// 	*uint, *uint8, *uint16, *uint32, *uint64
  /// 	*bool
  /// 	*float32, *float64
  /// 	*interface{}
  /// 	*RawBytes
  /// 	*Rows (cursor value)
  /// 	any type implementing Scanner (see Scanner docs)
  /// 
  /// In the most simple case, if the type of the value from the source
  /// column is an integer, bool or string type T and dest is of type *T,
  /// Scan simply assigns the value through the pointer.
  /// 
  /// Scan also converts between string and numeric types, as long as no
  /// information would be lost. While Scan stringifies all numbers
  /// scanned from numeric database columns into *string, scans into
  /// numeric types are checked for overflow. For example, a float64 with
  /// value 300 or a string with value "300" can scan into a uint16, but
  /// not into a uint8, though float64(255) or "255" can scan into a
  /// uint8. One exception is that scans of some float64 numbers to
  /// strings may lose information when stringifying. In general, scan
  /// floating point columns into *float64.
  /// 
  /// If a dest argument has type *[]byte, Scan saves in that argument a
  /// copy of the corresponding data. The copy is owned by the caller and
  /// can be modified and held indefinitely. The copy can be avoided by
  /// using an argument of type [*RawBytes] instead; see the documentation
  /// for [RawBytes] for restrictions on its use.
  /// 
  /// If an argument has type *interface{}, Scan copies the value
  /// provided by the underlying driver without conversion. When scanning
  /// from a source value of type []byte to *interface{}, a copy of the
  /// slice is made and the caller owns the result.
  /// 
  /// Source values of type [time.Time] may be scanned into values of type
  /// *time.Time, *interface{}, *string, or *[]byte. When converting to
  /// the latter two, [time.RFC3339Nano] is used.
  /// 
  /// Source values of type bool may be scanned into types *bool,
  /// *interface{}, *string, *[]byte, or [*RawBytes].
  /// 
  /// For scanning into *bool, the source may be true, false, 1, 0, or
  /// string inputs parseable by [strconv.ParseBool].
  /// 
  /// Scan can also convert a cursor returned from a query, such as
  /// "select cursor(select * from my_table) from dual", into a
  /// [*Rows] value that can itself be scanned from. The parent
  /// select query will close any cursor [*Rows] if the parent [*Rows] is closed.
  /// 
  /// If any of the first arguments implementing [Scanner] returns an error,
  /// that error will be wrapped in the returned error.
  fn Scan(self: Ref<Rows>, dest: VarArgs<Unknown>) -> Result<(), error>
}

impl Stmt {
  /// Close closes the statement.
  #[allow(unused_result)]
  fn Close(self: Ref<Stmt>) -> Result<(), error>

  /// Exec executes a prepared statement with the given arguments and
  /// returns a [Result] summarizing the effect of the statement.
  /// 
  /// Exec uses [context.Background] internally; to specify the context, use
  /// [Stmt.ExecContext].
  fn Exec(self: Ref<Stmt>, args: VarArgs<Unknown>) -> Result<Result, error>

  /// ExecContext executes a prepared statement with the given arguments and
  /// returns a [Result] summarizing the effect of the statement.
  fn ExecContext(self: Ref<Stmt>, ctx: context.Context, args: VarArgs<Unknown>) -> Result<Result, error>

  /// Query executes a prepared query statement with the given arguments
  /// and returns the query results as a *Rows.
  /// 
  /// Query uses [context.Background] internally; to specify the context, use
  /// [Stmt.QueryContext].
  fn Query(self: Ref<Stmt>, args: VarArgs<Unknown>) -> Result<Ref<Rows>, error>

  /// QueryContext executes a prepared query statement with the given arguments
  /// and returns the query results as a [*Rows].
  fn QueryContext(self: Ref<Stmt>, ctx: context.Context, args: VarArgs<Unknown>) -> Result<Ref<Rows>, error>

  /// QueryRow executes a prepared query statement with the given arguments.
  /// If an error occurs during the execution of the statement, that error will
  /// be returned by a call to Scan on the returned [*Row], which is always non-nil.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, the [*Row.Scan] scans the first selected row and discards
  /// the rest.
  /// 
  /// Example usage:
  /// 
  /// 	var name string
  /// 	err := nameByUseridStmt.QueryRow(id).Scan(&name)
  /// 
  /// QueryRow uses [context.Background] internally; to specify the context, use
  /// [Stmt.QueryRowContext].
  fn QueryRow(self: Ref<Stmt>, args: VarArgs<Unknown>) -> Ref<Row>

  /// QueryRowContext executes a prepared query statement with the given arguments.
  /// If an error occurs during the execution of the statement, that error will
  /// be returned by a call to Scan on the returned [*Row], which is always non-nil.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, the [*Row.Scan] scans the first selected row and discards
  /// the rest.
  fn QueryRowContext(
    self: Ref<Stmt>,
    ctx: context.Context,
    args: VarArgs<Unknown>,
  ) -> Ref<Row>
}

impl Tx {
  /// Commit commits the transaction.
  fn Commit(self: Ref<Tx>) -> Result<(), error>

  /// Exec executes a query that doesn't return rows.
  /// For example: an INSERT and UPDATE.
  /// 
  /// Exec uses [context.Background] internally; to specify the context, use
  /// [Tx.ExecContext].
  fn Exec(self: Ref<Tx>, query: string, args: VarArgs<Unknown>) -> Result<Result, error>

  /// ExecContext executes a query that doesn't return rows.
  /// For example: an INSERT and UPDATE.
  fn ExecContext(
    self: Ref<Tx>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Result<Result, error>

  /// Prepare creates a prepared statement for use within a transaction.
  /// 
  /// The returned statement operates within the transaction and will be closed
  /// when the transaction has been committed or rolled back.
  /// 
  /// To use an existing prepared statement on this transaction, see [Tx.Stmt].
  /// 
  /// Prepare uses [context.Background] internally; to specify the context, use
  /// [Tx.PrepareContext].
  fn Prepare(self: Ref<Tx>, query: string) -> Result<Ref<Stmt>, error>

  /// PrepareContext creates a prepared statement for use within a transaction.
  /// 
  /// The returned statement operates within the transaction and will be closed
  /// when the transaction has been committed or rolled back.
  /// 
  /// To use an existing prepared statement on this transaction, see [Tx.Stmt].
  /// 
  /// The provided context will be used for the preparation of the context, not
  /// for the execution of the returned statement. The returned statement
  /// will run in the transaction context.
  fn PrepareContext(self: Ref<Tx>, ctx: context.Context, query: string) -> Result<Ref<Stmt>, error>

  /// Query executes a query that returns rows, typically a SELECT.
  /// 
  /// Query uses [context.Background] internally; to specify the context, use
  /// [Tx.QueryContext].
  fn Query(self: Ref<Tx>, query: string, args: VarArgs<Unknown>) -> Result<Ref<Rows>, error>

  /// QueryContext executes a query that returns rows, typically a SELECT.
  fn QueryContext(
    self: Ref<Tx>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Result<Ref<Rows>, error>

  /// QueryRow executes a query that is expected to return at most one row.
  /// QueryRow always returns a non-nil value. Errors are deferred until
  /// [Row]'s Scan method is called.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, the [*Row.Scan] scans the first selected row and discards
  /// the rest.
  /// 
  /// QueryRow uses [context.Background] internally; to specify the context, use
  /// [Tx.QueryRowContext].
  fn QueryRow(self: Ref<Tx>, query: string, args: VarArgs<Unknown>) -> Ref<Row>

  /// QueryRowContext executes a query that is expected to return at most one row.
  /// QueryRowContext always returns a non-nil value. Errors are deferred until
  /// [Row]'s Scan method is called.
  /// If the query selects no rows, the [*Row.Scan] will return [ErrNoRows].
  /// Otherwise, the [*Row.Scan] scans the first selected row and discards
  /// the rest.
  fn QueryRowContext(
    self: Ref<Tx>,
    ctx: context.Context,
    query: string,
    args: VarArgs<Unknown>,
  ) -> Ref<Row>

  /// Rollback aborts the transaction.
  fn Rollback(self: Ref<Tx>) -> Result<(), error>

  /// Stmt returns a transaction-specific prepared statement from
  /// an existing statement.
  /// 
  /// Example:
  /// 
  /// 	updateMoney, err := db.Prepare("UPDATE balance SET money=money+? WHERE id=?")
  /// 	...
  /// 	tx, err := db.Begin()
  /// 	...
  /// 	res, err := tx.Stmt(updateMoney).Exec(123.45, 98293203)
  /// 
  /// The returned statement operates within the transaction and will be closed
  /// when the transaction has been committed or rolled back.
  /// 
  /// Stmt uses [context.Background] internally; to specify the context, use
  /// [Tx.StmtContext].
  fn Stmt(self: Ref<Tx>, stmt: Ref<Stmt>) -> Ref<Stmt>

  /// StmtContext returns a transaction-specific prepared statement from
  /// an existing statement.
  /// 
  /// Example:
  /// 
  /// 	updateMoney, err := db.Prepare("UPDATE balance SET money=money+? WHERE id=?")
  /// 	...
  /// 	tx, err := db.Begin()
  /// 	...
  /// 	res, err := tx.StmtContext(ctx, updateMoney).Exec(123.45, 98293203)
  /// 
  /// The provided context is used for the preparation of the statement, not for the
  /// execution of the statement.
  /// 
  /// The returned statement operates within the transaction and will be closed
  /// when the transaction has been committed or rolled back.
  fn StmtContext(self: Ref<Tx>, ctx: context.Context, stmt: Ref<Stmt>) -> Ref<Stmt>
}