diff options
| author | Shulhan <ms@kilabit.info> | 2026-04-07 21:56:06 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2026-04-07 21:56:16 +0700 |
| commit | 6874d73f26a1b68e44c04a55c29cd0e82244e5f0 (patch) | |
| tree | 4bdab5c28f99bee0359aa2ac37610d9e0474249a | |
| parent | 5d61c25421e04d263cd89fbd7e4f428e50b348d5 (diff) | |
| download | pakakeh.go-6874d73f26a1b68e44c04a55c29cd0e82244e5f0.tar.xz | |
lib/sql: add method Meta to Client
The Meta method returns new instance of [Meta] based on the current
client driver and kind arugment.
While at it, update comments on most methods to use adjectives.
| -rw-r--r-- | lib/sql/client.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/sql/client.go b/lib/sql/client.go index b553bde5..b9d3eefb 100644 --- a/lib/sql/client.go +++ b/lib/sql/client.go @@ -23,14 +23,14 @@ const ( sqlExtension = ".sql" ) -// Client provide a wrapper for generic database instance. +// Client provides a wrapper for generic database instance. type Client struct { *sql.DB ClientOptions TableNames []string // List of tables in database. } -// NewClient create and initialize new database client. +// NewClient creates and initializes new database client. func NewClient(opts ClientOptions) (cl *Client, err error) { db, err := sql.Open(opts.DriverName, opts.DSN) if err != nil { @@ -45,7 +45,7 @@ func NewClient(opts ClientOptions) (cl *Client, err error) { return cl, nil } -// FetchTableNames return the table names in current database schema sorted +// FetchTableNames returns the table names in current database schema sorted // in ascending order. func (cl *Client) FetchTableNames() (tableNames []string, err error) { var logp = `FetchTableNames` @@ -93,7 +93,12 @@ func (cl *Client) FetchTableNames() (tableNames []string, err error) { return cl.TableNames, nil } -// Migrate the database using list of SQL files inside a directory. +// Meta returns new instance of [Meta] for DML kind. +func (cl *Client) Meta(kind DMLKind) *Meta { + return NewMeta(cl.DriverName, kind) +} + +// Migrate migratest the database using list of SQL files inside a directory. // Each SQL file in directory will be executed in alphabetical order based on // the last state. // @@ -183,8 +188,8 @@ func (cl *Client) Migrate(tableMigration string, fs *memfs.MemFS) (err error) { return nil } -// migrateInit get the last file in table migration or if its not exist create -// the migration table. +// migrateInit returns the last file in table migration or if its not exist +// create the migration table. func (cl *Client) migrateInit(tableMigration string) (lastFile string, err error) { lastFile, err = cl.migrateLastFile(tableMigration) if err == nil { @@ -199,8 +204,8 @@ func (cl *Client) migrateInit(tableMigration string) (lastFile string, err error return "", nil } -// migrateLastFile return the last finished migration or empty string if table -// migration does not exist. +// migrateLastFile returns the last finished migration or empty string if +// table migration does not exist. func (cl *Client) migrateLastFile(tableMigration string) (file string, err error) { q := ` SELECT filename |
