danvk/pg-to-ts

Bug: composite primary keys are returned incorrectly

Opened this issue · 0 comments

Tables with multiple fields as part of the primary key incorrectly report the primary key
consider:

CREATE TABLE public.friends (
	userid int8 NOT NULL,
	friendid int8 NOT NULL,
	relationship text not null,
  -- more columns
	CONSTRAINT friends_pkey PRIMARY KEY (userid, friendid),

Will incorrectly generate the following: (abbreviated for clarity)

const friends = {
  tableName: 'friends',
  columns: ['userid', 'friendid', 'relationship'],
  primaryKey: 'userid',  // should be ['userid', 'friendid']
} as const;

I had hoped to use your wonderful tool to automatically generate some extremely simple CRUD

friends_insert_one(); 
friends_update_one(userid, friendid, { relationship });
friends_get_one(userid, friendid);
friends_get_by_userid();   // primaryKey[0]
friends_get_by_friendid(); //primaryKey[1]