The terminology is not necessarily used consistently. In fact, it says that here:
https://en.wikipedia.org/wiki/Code-mixingThere are several different concepts:
1. Code-switching is an active process in bilinguals, using two languages in a single sentence/conversation, but not necessarily 'changing' either language. Importantly, both speakers must be bilingual (or at least have some basic knowledge) for this to make sense. Importantly, code-switching is typically not conventionalized in a speech community. It's "made up" as they speak. (That isn't to say it's unstructured: for example, some phrasal boundaries are likely to be places where the language switches, and there is a lot of research about that sort of thing.)
2. A mixed language is one where two varieties have thoroughly mixed to the point of having a sort of conventional hybrid. An example is Quechua+Spanish 'Media Lengua', or (Guarani+Spanish) Jopara in Paraguay. These are similar to pidgins and creoles in some sense but have a mixing rather than acquisition origin. Conventionalized code-switching could lead to a mixed language.
I think "code-mixing" can refer to either of the above.
3. Borrowing is a lexical process (well, usually lexical, rarely something like phonemes, but also sometimes syntactic constructions or morphology), where one language "borrows" a word (etc.) from another language and incorporates it. An extreme case of borrowing might end up looking like a mixed language, so the difference may be in the extent. But there is fairly clearly a difference in most cases. Of course some people have called English a "creole" because of all of the borrowed French/Danish/etc. words, so I suppose that is exactly their argument (but not the most popular interpretation in that case). As for code-switching vs. borrowing, the distinction is that borrowing is a conventionalization process, while code-switching is just a using-in-the-moment process. You could say, I guess, that borrowing is conventionalized code-switching, although that would be misleading in terms of extent (since code-switching rarely results in borrowing, and fewer words are borrowed than are used in code-switching).