Not only did a federal judge hand President Trump a stinging defeat Monday on his attempts to block a House subpoena of his financial records, he did it by explicitly lumping Trump in with one of the nation’s worst presidents.

If only Trump knew enough history to feel the burn.

Judge Amit Mehta opened his decision by quoting President James Buchanan protesting against a congressional investigation, claiming that it was merely a means of “furnishing material for harassing [the President], degrading him in the eyes of the country.”

I do, therefore, . . . solemnly protest against these proceedings of the House of Representatives, because they are in violation of the rights of the coordinate executive branch of the Government, and subversive of its constitutional independence; because they are calculated to foster a band of interested parasites and informers, ever ready, for their own advantage, to swear before ex parte committees to pretended private conversations between the President and themselves, incapable, from their nature, of being disproved; thus furnishing material for harassing him, degrading him in the eyes of the country . . . – President James Buchanan

Buchanan, whose feckless presidency was defined by the Dred Scott decision and his invertebrate response to the secession of the South, was objecting to the House’s decision to investigate whether his administration had sought to improperly influence the actions of Congress.

He argued that Congress had no general powers to investigate him, outside of formal impeachment proceedings. If Congress were allowed to investigate his conduct outside of impeachment, he warned, it “would establish a precedent dangerous and embarrassing to all my successors, to whatever political party they might be attached.”

“Some 160 years later,” wrote Judge Mehta, “President Donald J. Trump has taken up the fight of his predecessor.”

And not just on matters regarding his financial records: When Trump was asked why his administration told former White House counsel Don McGahn not to testify before Congress, he replied : “As I understand it they’re doing that for the office of the presidency for future presidents. As I understand it it’s a very important precedent. The attorneys say they’re doing it not for me, they’re doing it for the future.”

Judge Mehta dwells on the Buchananite logic of Trump’s attempts to defy a congressional probe.

Echoing the protests of President Buchanan, President Trump and his associated entities are before this court, claiming that the Oversight Committee’s subpoena to Mazars exceeds the Committee’s constitutional power to conduct investigations. The President argues that there is no legislative purpose for the subpoena. The Oversight Committee’s true motive, the President insists, is to collect personal information about him solely for political advantage. He asks the court to declare the Mazars subpoena invalid and unenforceable. Courts have grappled for more than a century with the question of the scope of Congress’s investigative power. The binding principle that emerges from these judicial decisions is that courts must presume Congress is acting in furtherance of its constitutional responsibility to legislate and must defer to congressional judgments about what Congress needs to carry out that purpose. To be sure, there are limits on Congress’s investigative authority. But those limits do not substantially constrain Congress. So long as Congress investigates on a subject matter on which “legislation could be had,” Congress acts as contemplated by Article I of the Constitution.

Specifically, wrote Judge Mehta, the financial records sought by Congress would “aid its consideration of strengthening ethics and disclosure laws, as well as amending the penalties for violating such laws. The Committee also says that the records will assist in monitoring the President’s compliance with the Foreign Emoluments Clauses.” The judge ruled that these were “facially valid legislative purposes,” regardless of the political motivations or considerations.

He rejects Trump’s arguments categorically.

It is simply not fathomable that a Constitution that grants Congress the power to remove a President for reasons including criminal behavior would deny Congress the power to investigate him for unlawful conduct — past or present — even without formally opening an impeachment inquiry.

As it turns out, the investigation that so upset Buchanan uncovered massive corruption, and the fallout was dramatic. As historian Jasmin Bath noted: “By uncovering corrupt White House acts, Buchanan’s congressional opponents dismantled his authority and paved the way for a member of their own party to win the presidency during the next election.”

Nicknamed the Covode Committee after its chairman, John Covode, it produced a detailed majority report that exposed the crimes of the Democratic Party and the president himself. The sheer volume of corruption uncovered was startling. Although there was not enough evidence to impeach Buchanan, the report exposed extensive corruption that took place during his presidency: bribery, the disfranchisement of some voters in federal elections, abuses of printing contracts, subsidies for partisan presses from public accounts. The list went on and on… The committee’s findings were released to the public in June 1860, just months before the presidential election, and proved to be incredibly damaging to the Democratic Party’s reputation, even though Buchanan was not running again. Its detailed accounts of the misdeeds of the Democratic administration, which circulated throughout the North, gave the Republican Party substantial evidence with which to persuade the public that the United States could not afford the continued reign of the “rotten and dishonest” Democratic politicians.

Not surprisingly, Trump lashed out at Mehta’s ruling, calling it a “totally the wrong decision by, obviously, an Obama-appointed judge.” It has already been appealed.

But it’s probably too much to hope that our ahistorical president fully felt the sting of the judge’s link to Buchanan. Historians may differ on the exact membership of the Worst Presidents Club, but James Buchanan (along with Andrew Johnson and Warren Harding) is an almost universal choice.

It’s not a club Trump wants to join.