Module h2o_wave.db
Functions
connect
Returns a connection to a database server.
- Args
- -----=
address- the address of the database server http(s)://ip:port. Defaults to http://127.0.0.1:10100
key_id- the API access key ID. Defaults to the environment variable H2O_WAVEDB_ACCESS_KEY_ID.
key_secret- the API access key secret. Defaults to the environment variable H2O_WAVEDB_ACCESS_KEY_SECRET.
Returns -----= a connection instance
Classes
WaveDB
Represents a database connector.
Methods
drop
Drop the database.
exec
Execute a single SQL statement. Parameters are optional.
Returns a (result, error) tuple, where result is a 2-dimensional list in row-major order, and error is a string error message, if any. The result will be None if the error is not None. Therefore, always check if there is an error before attempting to use the result.
- Args
- -----=
sql- SQL statement
params- Parameters to the SQL statement, one of str, int, float or None
Returns -----= A (result, error) tuple Example:
result, err = db.exec(sql) if err: print(error) return print(result)
result, error = db.exec('CREATE TABLE student(name TEXT, age INTEGER)') result, error = db.exec('INSERT INTO student VALUES ("Alice", 18)') result, error = db.exec('INSERT INTO student VALUES (?, ?)', "Bob", 19) result, error = db.exec('SELECT name, age FROM student WHERE age > 17') result, error = db.exec('SELECT name, age FROM student WHERE age > ?', 17)
exec_atomic
Same as exec_may(), but use a transaction. Rollback if any statement fails.
exec_many
Execute multiple SQL statements.
Returns a (results, error) tuple, where results is a list of results from each statement, and error is a string error message, if any. The results will be None if the error is not None. Therefore, always check if there is an error before attempting to use the results.
- Args
- -----=
args- SQL statements
Returns -----= a (results, error) tuple Example:
results, error = db.exec_many( 'CREATE TABLE student(name TEXT, age INTEGER)', 'INSERT INTO student VALUES ("Alice", 18)', ('INSERT INTO student VALUES (?, ?)', "Bob", 19), 'SELECT name, age FROM student WHERE age > 17', ('SELECT name, age FROM student WHERE age > ?', 17), ) if err: print(error) return print(results)