Initially David had doubts if he could be a king, since he was a descendant of Ruth, a Moabite, and the Torah said that “Moav should not enter the Jewish people.” The loophole was that “Moav” was male, so females of Moav, that is Ruth, could enter – but not everyone agreed to it. However, later he found a hint in the worlds of the angel, who says to Lot, “Take the daughters found with you.” About David himself God says, “I have found David, my servant”. So David found a hint to himself in the Torah. But since he calls it a “scroll”, it means that it was written and given to Jews scroll by scroll.
Others say that it was written as a whole, since God tells Moses, “Take this book of the Torah”. What about the “scroll” proof? – The whole Torah is also called a scroll. But what about “this book” proof? – That is after it was glued together.
Furthermore, even though the Torah was written down, a larger body of knowledge was only taught from teacher to student and never written down. What is the proof? “Write for yourself these words” means that some words are to be written down, but “On the basis of these words” alludes to portions that are to be guarded and transmitted orally. Later on it was too hard for the people to remember everything, and even oral teaching were written down – and this it the Talmud.
Art: King David by Juan Correa de Vivar