Was the OT written to fit the story of David?
Biblical errancy isn't the ideal place for this question, but I'll give it a shot here, anyway. I recently ran across the conjecture that Biblical events going all the way back to Genesis were tweaked or even fully created to prepare the reader/hearer for the exploits of King David, who in this line of thinking is the central figure of the ancient Hebrew religion, kind of like the Hebrew Gilgamesh. In support of this hypothesis, it is suggested that all of the stories describing sons lower in the birthing order being more successful than their elder brothers is meant to remove the oddness of David, being the baby brother in his own family, being selected to replace Saul. This story does repeat several times in the stories of the patriarchs: Isaac is selected over Ishmael, Jacob over Esau and Joseph over his ten older brothers. Furthermore, there are stories of the patriarchs deceiving people and engaging in sexual dalliances, all of which are at least similar to David's exploits, and could potentially serve as some kind of apologetic ammunition. I'll admit to finding this idea very compelling, and I'd like to know if the scholars have much to say on the subject.
"The whole conception of God is a conception derived from ancient Oriental despotisms. It is a conception quite unworthy of free men."