Refactoring and adding sql libraries

boctor2 termaat1