diff --git a/src/Connection.zig b/src/Connection.zig index 7b224e9..2075b74 100644 --- a/src/Connection.zig +++ b/src/Connection.zig @@ -45,6 +45,8 @@ pub const ConnectionOptions = struct { environment: odbc.Environment, connection: odbc.Connection, +/// Initialize a new Connection instance with the given ODBC version. The default version is 3.0. +/// This does not connect to a database. pub fn init(config: ConnectionOptions) !Connection { var connection: Connection = undefined; @@ -58,10 +60,13 @@ pub fn init(config: ConnectionOptions) !Connection { return connection; } +/// Connect to a database using a server/host, username, and password. pub fn connect(conn: *Connection, server_name: []const u8, username: []const u8, password: []const u8) !void { try conn.connection.connect(server_name, username, password); } +/// Connect to a database using a ConnectionConfig. The config will be converted to a connection string, and then +/// it will attempt to connect using connectExtended. pub fn connectWithConfig(conn: *Connection, allocator: Allocator, connection_config: ConnectionConfig) !void { var connection_string = try connection_config.getConnectionString(allocator); defer allocator.free(connection_string); @@ -69,23 +74,31 @@ pub fn connectWithConfig(conn: *Connection, allocator: Allocator, connection_con try conn.connection.connectExtended(connection_string, .NoPrompt); } +/// Connect using a pre-created connection string. pub fn connectExtended(conn: *Connection, connection_string: []const u8) !void { try conn.connection.connectExtended(connection_string, .NoPrompt); } +/// Close the connection and environment handles. Does not disconnect from the data source. pub fn deinit(self: *Connection) void { self.connection.deinit() catch {}; self.environment.deinit() catch {}; } +/// Disconnect from the currently connected data source. pub fn disconnect(self: *Connection) void { self.connection.disconnect() catch {}; } +/// Sets the commit mode which will be used in all cursors created from this connection. +/// If the commit mode is `auto`, then each statement execution will be immediately committed. If the +/// commit mode is `manual` then statement executions won't be commited until the user calls `cursor.commit()`. +/// This can be used for transaction management. pub fn setCommitMode(self: *Connection, mode: CommitMode) !void { try self.connection.setAttribute(.{ .Autocommit = mode == .auto }); } +/// Get a new cursor, with which you can execute SQL statements. pub fn getCursor(self: *Connection, allocator: Allocator) !Cursor { return try Cursor.init(allocator, self.connection); }