func WithInstance(ctx context.Context, db *sql.DB) (*MySQL, error) {
	conn, err := db.Conn(ctx)
	if err != nil {
		return nil, err
	}

	p := MySQL{conn: conn}

	if err := conn.PingContext(ctx); err != nil {
		return nil, fmt.Errorf("could not ping to MySQL database: %w", err)
	}

	var databaseName sql.NullString
	if err := db.QueryRow(`SELECT DATABASE()`).Scan(&databaseName); err != nil {
		return nil, err
	}

	if len(databaseName.String) == 0 {
		return nil, ErrNoDatabaseName
	}

	p.DatabaseName = databaseName.String

	if len(p.EventStoreTable) == 0 {
		p.EventStoreTable = DefaultEventStoreTable
	}

	if err := p.ensureTable(ctx); err != nil {
		return nil, err
	}

	return &p, nil
}
// WithInstance creates a mysql data store with an existing db connection
WithInstance creates a mysql data store with an existing db connection
// WithInstance creates a mysql data store with an existing db connection
func WithInstance(ctx context.Context, db *sql.DB) (*MySQL, error) {
	conn, err := db.Conn(ctx)
	if err != nil {
		return nil, err
	}
	p := MySQL{conn: conn}
	if err := conn.PingContext(ctx); err != nil {
		return nil, fmt.Errorf("could not ping to MySQL database: %w", err)
	}
	var databaseName sql.NullString
	if err := db.QueryRow(`SELECT DATABASE()`).Scan(&databaseName); err != nil {
		return nil, err
	}
	if len(databaseName.String) == 0 {
		return nil, ErrNoDatabaseName
	}
	p.DatabaseName = databaseName.String
	if len(p.EventStoreTable) == 0 {
		p.EventStoreTable = DefaultEventStoreTable
	}
	if err := p.ensureTable(ctx); err != nil {
		return nil, err
	}
	return &p, nil
}
func WithInstance ( ctx context . Context , db * sql . DB ) ( * MySQL , error ) { conn , err := db . Conn ( ctx ) if err != nil { return nil , err } p := MySQL { conn : conn } if err := conn . PingContext ( ctx ) ; err != nil { return nil , fmt . Errorf ( " " , err ) } var databaseName sql . NullString if err := db . QueryRow ( `SELECT DATABASE()` ) . Scan ( & databaseName ) ; err != nil { return nil , err } if len ( databaseName . String ) == 0 { return nil , ErrNoDatabaseName } p . DatabaseName = databaseName . String if len ( p . EventStoreTable ) == 0 { p . EventStoreTable = DefaultEventStoreTable } if err := p . ensureTable ( ctx ) ; err != nil { return nil , err } return & p , nil }
WithInstance creates a mysql data store with an existing db connection
WithInstance creates a mysql data store with an existing db connection