From 7f260c3ae094f666cd861994294220bccbd6da29 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Sat, 9 May 2020 14:32:54 +0300 Subject: [PATCH] entc/gen/template: remove irrelevant code from templates (#481) --- entc/gen/internal/bindata.go | 8 ++-- entc/gen/template/base.tmpl | 9 ----- entc/gen/template/dialect/sql/globals.tmpl | 34 +---------------- entc/integration/config/ent/ent.go | 42 --------------------- entc/integration/customid/ent/ent.go | 43 ---------------------- entc/integration/ent/ent.go | 42 --------------------- entc/integration/gremlin/ent/ent.go | 9 ----- entc/integration/hooks/ent/ent.go | 42 --------------------- entc/integration/idtype/ent/ent.go | 42 --------------------- entc/integration/json/ent/ent.go | 42 --------------------- entc/integration/migrate/entv1/ent.go | 42 --------------------- entc/integration/migrate/entv2/ent.go | 42 --------------------- entc/integration/privacy/ent/ent.go | 42 --------------------- entc/integration/template/ent/ent.go | 42 --------------------- examples/edgeindex/ent/ent.go | 42 --------------------- examples/entcpkg/ent/ent.go | 42 --------------------- examples/m2m2types/ent/ent.go | 42 --------------------- examples/m2mbidi/ent/ent.go | 42 --------------------- examples/m2mrecur/ent/ent.go | 42 --------------------- examples/o2m2types/ent/ent.go | 42 --------------------- examples/o2mrecur/ent/ent.go | 42 --------------------- examples/o2o2types/ent/ent.go | 42 --------------------- examples/o2obidi/ent/ent.go | 42 --------------------- examples/o2orecur/ent/ent.go | 42 --------------------- examples/start/ent/ent.go | 42 --------------------- examples/traversal/ent/ent.go | 42 --------------------- 26 files changed, 5 insertions(+), 980 deletions(-) diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index f8a7a4959..29b61a2a4 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -126,7 +126,7 @@ func (fi bindataFileInfo) Sys() interface{} { return nil } -var _templateBaseTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x58\x5f\x4f\xdc\x46\x10\x7f\x3e\x7f\x8a\x91\x75\x4d\x6d\x72\xd8\x84\xb7\x46\xe2\x81\xd0\xd0\x22\x25\x24\x15\x69\xf3\x10\x45\xd5\x62\x8f\x7d\x2b\xec\x5d\xb3\xbb\x06\x4e\x96\xbf\x7b\x35\xbb\xfe\x7b\x5c\x80\x84\x34\x0f\x91\x6f\x66\x77\xfe\xfd\x7e\x33\x1e\xd3\x34\xf1\x9e\x77\x22\xab\x8d\xe2\xf9\xda\xc0\xe1\xc1\xab\xdf\xf6\x2b\x85\x1a\x85\x81\x53\x96\xe0\xa5\x94\x57\x70\x26\x92\x08\x8e\x8b\x02\xec\x21\x0d\xa4\x57\x37\x98\x46\xde\xa7\x35\xd7\xa0\x65\xad\x12\x84\x44\xa6\x08\x5c\x43\xc1\x13\x14\x1a\x53\xa8\x45\x8a\x0a\xcc\x1a\xe1\xb8\x62\xc9\x1a\xe1\x30\x3a\xe8\xb5\x90\xc9\x5a\xa4\x1e\x17\x56\xff\xee\xec\xe4\xed\xf9\xc5\x5b\xc8\x78\x81\xd0\xc9\x94\x94\x06\x52\xae\x30\x31\x52\x6d\x40\x66\x60\x26\xce\x8c\x42\x8c\xbc\xbd\xb8\x6d\x3d\xaf\x69\x20\xc5\x8c\x0b\x04\xff\x92\x69\xf4\xa1\x13\x2e\xab\xab\x1c\x5e\x1f\x01\x09\x61\x19\x9d\x48\x91\xf1\x3c\xfa\xc8\x92\x2b\x96\x23\x1d\x6a\x1a\x30\x58\x56\x05\x33\x08\xfe\x1a\x59\x8a\xca\x87\x65\x7f\x7d\x54\xf1\xb2\x92\xca\xf4\xaa\x38\x06\xaa\x0e\x2b\x38\xd3\xa8\xc1\x48\x60\x37\x92\xa7\xe0\x4e\x41\x22\x45\x56\xf0\xc4\x50\x1e\xb5\x46\xf5\xab\xb6\x95\x89\x3c\xb3\xa9\x10\x02\x6f\xf1\xa1\x82\xfe\xdf\x11\x59\x8a\x3e\x54\xde\xe2\x4f\xaa\xf3\x54\x48\x02\x6f\xf1\x0f\x2b\x6a\x9c\x8a\xad\xc0\x5b\xfc\x55\xa3\xda\x4c\xe5\x56\xe0\x2d\x3e\xca\x82\x27\x9b\x89\xdc\x09\xbc\xc5\xfb\xda\x30\x23\xd5\xa8\xe8\x04\x9d\x86\x4b\x31\xd7\x70\x29\x3a\x15\x9e\xd6\x22\x99\xaa\xac\xc0\x0b\x6d\x21\x3e\xa8\x14\x95\x3d\xc0\xaa\xaa\xe0\xa8\x81\x09\x90\x24\xe4\x22\x07\x29\x00\xb9\x59\xa3\x82\x5c\xb1\x6a\x0d\x46\xb1\x1b\x54\x9a\x15\x20\x15\xe8\xeb\x02\x34\x16\x16\xde\xae\x38\xa3\xb5\xac\x16\x49\x40\x10\x46\x17\x46\x2a\x96\x63\xf4\xa6\xe6\x05\xd1\xa9\x6d\x43\x8b\x8e\x62\x22\x47\x58\x66\x2b\x58\x5a\x7f\x04\xb4\x7b\x68\x5b\x6f\x41\x57\x33\x38\x82\x8a\xe9\x84\x15\xf4\x4c\xd2\x38\x06\xa7\x68\xdb\x21\x5e\xa2\x5a\xce\x6f\x50\x40\xc6\xb1\x48\x35\xc1\xd6\x34\x50\x57\x15\xaa\xee\xa8\x35\x1b\x79\x0b\x0a\x6a\x30\x10\x74\xc7\xa3\x28\xd2\x86\xb2\x0d\x27\xe1\x37\xde\x62\xd1\x34\xfb\x70\xcb\xcd\x1a\xf0\xce\xa0\x48\x21\xe0\x22\xc5\x3b\x58\x46\xe7\x32\x45\x0d\x07\x21\xf8\x74\xd6\x27\x73\xbe\xbd\xea\xf7\xa9\xec\x53\xb0\x0b\x9b\x84\x29\xab\x82\x52\xab\x14\x17\x26\x03\x3f\xe5\x8c\x4a\x16\xff\xa2\x63\xd9\xdd\xe9\x4b\x04\xee\x96\x42\x53\x2b\x9b\xc3\xdd\xc0\x60\x67\x26\x72\x27\x9a\x06\x28\x1e\xeb\xc4\xf6\x00\xfd\xea\x5b\xe6\x01\x7f\xb9\x92\x75\x15\x6b\x9e\x0b\x66\x6a\x85\x5b\x9e\xe3\x18\x8e\xf3\x5c\x61\xde\x33\x66\x42\x08\xd6\x29\x88\x65\xda\x60\x45\xc4\xb0\x75\x27\x8b\xfb\x97\x9b\x91\x18\xf1\xc8\x88\x6f\x25\x60\x79\x77\xac\x69\xd2\x30\xa8\x34\xd6\xa9\x9c\x39\x20\x94\xdc\x83\x54\xa0\x50\xb0\x92\xa8\xc8\x84\xb4\x44\x74\xff\xf7\x67\xb4\x43\x28\xa9\xb5\x91\x25\x08\x56\xa2\x8e\xe0\x54\x2a\xc0\x3b\x56\x56\x05\xbe\xf6\xe2\xd8\x8b\xe3\xc5\x1f\x14\xe8\x9b\x8d\xc3\xfc\xd5\xca\x51\xe5\x30\x8c\x48\x37\x64\x1d\xf4\x23\xa7\x6d\xa3\x63\x3d\xfd\x75\x51\x97\xdd\xd5\x70\x05\xbe\xae\xcb\x7f\xdd\x2f\x3f\x5c\xc1\x13\x6e\x1d\xce\x6e\x1d\xfa\xa1\x73\x7c\x91\x30\x11\x24\xe6\x6e\x05\x2f\x6e\x42\x0a\xd4\xf2\xf3\x58\x07\x99\x98\x43\xb1\xb2\x08\xf7\x2c\x9d\xa3\xd4\x78\x96\xa8\xae\xbe\x0f\xc0\xce\xf4\x36\xd3\x1e\xe1\x59\x3b\xed\x52\xaa\xec\x0a\x96\x54\xec\x53\xca\x81\x18\xd6\x63\x86\x63\xc3\x0a\xcb\xbc\xae\x65\xe9\xce\xa0\x7a\x94\x96\x89\x14\xda\x6c\x87\xd8\x34\xc0\x33\x58\x33\xfd\x69\x1e\x60\xdf\x06\x8f\xb4\xe7\x39\x2b\x89\xe5\x36\x90\xa1\x57\xc5\xa4\x3b\x1f\x6e\xb0\x2e\x82\xbe\xbb\x86\xe9\x23\xb6\xc7\x4f\xd3\xc0\x75\x2d\x0d\x0e\x39\xef\xe6\xb3\xb4\xc5\xe6\xd9\xb4\x8e\x6d\xbb\x35\xbf\xe8\x3d\x39\x38\x45\x96\xac\x5d\x93\xcd\xa6\x17\x05\x10\xec\x30\xe5\x0c\x38\x9e\x0c\x36\x76\x10\xe6\x7b\x46\x9b\x00\xff\x73\xef\xc2\x9f\xba\x7b\xda\x8c\x73\xe0\x66\xce\xd8\x4f\x1b\x74\x71\x0c\xe7\xd2\x9c\xd2\x06\xf2\x56\x29\x3b\x26\xc8\x94\x86\xdb\x35\x0a\x30\x6a\x43\x13\xc3\x48\xc8\xd0\x24\x6b\x60\xa0\x2b\x4c\x78\xc6\x13\x7a\x07\x72\xb3\x01\x26\x52\xe0\x06\x6e\x99\x06\x21\x8d\x5b\x65\xfa\xb5\x25\x65\x86\xd1\xc2\xd1\xbd\xd2\xe6\x7e\xb4\x51\x75\x62\xa8\x86\x05\xbb\xc4\xa2\xab\xb5\xe7\x42\x72\x47\x38\xcd\x9d\x12\x85\x71\xdc\x40\x27\x14\x06\x55\xc6\x12\x8c\x5c\x93\x07\x08\x7b\x33\xcb\xa1\xbb\x1d\x84\x9d\x49\x72\xd1\xd5\xc7\x1f\x47\xca\x6b\xf0\xe1\x25\x60\xe4\x9c\xbf\x04\x7f\x0c\xdf\xef\x82\x38\xd3\xbd\xdd\xa1\x28\x0c\x2e\xa5\x2c\x90\x09\xe0\x22\xe5\x09\x33\x64\xff\x76\x8d\x76\x92\x4e\x62\xa4\x93\x63\x39\xac\xb0\x0b\x77\x34\x1a\xa0\x52\x4e\x15\x5a\xab\x14\x27\xcf\x48\x02\x47\x47\x20\xb8\x15\xf4\x91\x67\xac\xd0\x48\xd0\x2d\x6e\x98\x82\xed\x94\x87\x04\xad\x39\x4d\xc3\x13\x95\x5a\xc1\x0b\x0c\xbb\x5c\xde\x33\x7d\x35\x64\x53\x32\x7d\x45\x70\xa9\x1d\xf1\x4d\x0f\x4e\x23\x74\x89\xb9\x10\xe7\x39\x84\xd3\x38\x05\x2f\x6c\x94\x63\x3c\xde\x40\xb2\x0b\x2e\xf2\xba\x60\xea\x69\x3c\xeb\x0e\x4f\x79\x56\x4a\x85\x54\x65\xea\x7f\xb4\x94\x7b\x84\x6e\x73\x8f\x3f\x99\x71\x33\xe3\xcf\x21\x5d\x9f\xea\x8c\x77\xbd\xf5\x1f\xa6\xde\x58\xc0\x6d\xf6\xf5\xa6\x9f\x4d\xc0\x59\x05\x1e\xe7\xe0\xb9\x34\xef\x24\x4b\xf1\xe1\x41\x93\xa3\xb1\x19\xa4\x04\x35\x1b\x27\x4b\x61\xaf\x02\x6d\x48\x6b\x84\x6b\xda\xf1\x47\xa0\xa7\x76\x47\x98\x31\xcd\xf1\xb9\x28\x4f\x2c\x7f\x1f\xc6\xd6\x39\x41\x6c\x1f\xe6\x59\xcc\x90\x76\x1e\x7e\x18\xe7\xae\x2e\xf7\x50\x76\x66\x9f\x8d\xf1\x24\xff\xc7\x11\x3e\xa1\xcd\x43\x31\x2e\xcc\x83\x10\x27\x0a\x99\xc1\xb8\xae\x52\x7a\x4f\x51\x2f\x4b\xe5\x9a\xdb\x36\xbb\xdb\x94\x53\x32\x38\xd5\xd9\xaf\x5e\xe4\x0a\x92\xc1\x8b\x86\x8c\xf1\x02\xd3\xd9\xa2\xba\x82\x1b\x2e\x0b\xb7\x30\xc8\xcc\x95\x5f\x2a\xb2\xe6\x5e\xea\xb5\xe0\xd7\x35\x0a\xd4\xba\xe3\xcf\x76\xd4\x23\x81\x4a\x9d\xf7\xfc\x59\xdc\x2a\x56\xb9\xcc\x7f\x88\x4b\x5b\x4e\x9e\xca\xa5\x31\xd7\x2e\xd5\x9e\x5e\xa5\xee\x39\xfd\xb7\xb0\xa1\xed\x0a\x44\x47\x9f\x15\xb3\x5f\x6f\xbb\xd8\x7d\x2f\x24\x67\x29\x98\x0c\xfb\x1e\xf0\x88\x14\x03\x69\xbf\x05\xf3\xf7\x50\x77\x2b\xb1\x5a\xe1\x40\xde\x2d\xf3\xcf\xa3\xf0\x96\xb1\x47\x38\xdc\x34\xf1\x1e\xe0\x5d\xc5\xfa\xb7\x22\x10\x43\x2c\x1d\x21\x2f\xe4\x25\x2b\x60\x8d\x45\x85\x4a\x47\x60\xff\xe0\x32\xec\x6c\x3b\x57\x36\xe7\x64\x6b\x5d\x7b\x68\x13\xdf\xb1\xc0\x2d\xbb\x3b\xf7\xbe\x4c\x77\x2f\x89\x36\xc8\xff\xc1\x25\xb7\x1f\x2a\xf7\xb6\xdb\xe8\xec\xf7\xe8\x13\x35\x91\xfb\xec\xbd\xc2\x8d\x1e\xe8\x40\x88\x93\x20\xe6\xa9\x86\x4c\xc9\xd2\x71\x80\xfa\xb1\x64\x55\x07\x37\x1d\x08\x4a\x12\x7c\xe9\xdc\xb4\xed\x57\xd7\x81\x4d\x1b\xc2\x97\xaf\x83\x94\x60\xd6\x14\x44\xc9\xae\x30\x98\x28\x56\x70\xb0\x82\x02\x45\x50\x86\xa1\xb7\xa0\x4f\x5d\x17\xac\xfb\xe0\x2a\x2d\x3d\x34\x1c\xd1\x77\x06\x8a\x34\xd0\x2b\xe0\x69\x38\xdd\x52\xb4\x37\x4d\xf7\xbf\x00\x00\x00\xff\xff\xd0\x7f\x3c\x96\x07\x14\x00\x00") +var _templateBaseTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\x5f\x6f\xd4\x38\x10\x7f\xde\x7c\x8a\x51\xb4\xc7\x6d\xca\x36\x81\xbe\x1d\x52\x1f\x4a\x45\xef\x90\xa0\x70\x2a\x77\x3c\x9e\xdc\x64\x92\x58\x75\xec\xd4\x76\xda\xae\xa2\xfd\xee\xa7\xb1\xf3\x77\x59\xba\x85\xc2\x03\xca\xce\xd8\xf3\xef\xf7\x9b\xc9\xa4\x6d\x9b\x1c\x05\xe7\xaa\xde\x68\x5e\x94\x16\x4e\x5e\xbd\xfe\xe3\xb8\xd6\x68\x50\x5a\xb8\x60\x29\x5e\x2b\x75\x03\xef\x65\x1a\xc3\x99\x10\xe0\x0e\x19\x20\xbd\xbe\xc3\x2c\x0e\xbe\x94\xdc\x80\x51\x8d\x4e\x11\x52\x95\x21\x70\x03\x82\xa7\x28\x0d\x66\xd0\xc8\x0c\x35\xd8\x12\xe1\xac\x66\x69\x89\x70\x12\xbf\xea\xb5\x90\xab\x46\x66\x01\x97\x4e\xff\xe1\xfd\xf9\xbb\xcb\xab\x77\x90\x73\x81\xd0\xc9\xb4\x52\x16\x32\xae\x31\xb5\x4a\x6f\x40\xe5\x60\x27\xce\xac\x46\x8c\x83\xa3\x64\xbb\x0d\x82\xb6\x85\x0c\x73\x2e\x11\xc2\x6b\x66\x30\x84\x4e\xb8\xac\x6f\x0a\x78\x73\x0a\x24\x84\x65\x7c\xae\x64\xce\x8b\xf8\x33\x4b\x6f\x58\x81\x74\xa8\x6d\xc1\x62\x55\x0b\x66\x11\xc2\x12\x59\x86\x3a\x84\x65\x7f\x7d\x54\xf1\xaa\x56\xda\xf6\xaa\x24\x01\xaa\x0e\x13\x9c\x19\x34\x60\x15\xb0\x3b\xc5\x33\xf0\xa7\x20\x55\x32\x17\x3c\xb5\x94\x47\x63\x50\xff\x6e\x5c\x65\xe2\xc0\x6e\x6a\x84\x55\xb0\xf8\x54\x43\xff\xef\x94\x2c\xc5\x9f\xea\x60\xf1\x17\xd5\x79\x2a\x24\x41\xb0\xf8\x97\x89\x06\xa7\x62\x27\x08\x16\x7f\x37\xa8\x37\x53\xb9\x13\x04\x8b\xcf\x4a\xf0\x74\x33\x91\x7b\x41\xb0\xf8\xd8\x58\x66\x95\x1e\x15\x9d\xa0\xd3\x70\x25\xe7\x1a\xae\x64\xa7\xc2\x8b\x46\xa6\x53\x95\x13\x04\x91\x2b\xc4\x27\x9d\xa1\x76\x07\x58\x5d\x0b\x8e\x06\x98\x04\x45\x42\x2e\x0b\x50\x12\x90\xdb\x12\x35\x14\x9a\xd5\x25\x58\xcd\xee\x50\x1b\x26\x40\x69\x30\xb7\x02\x0c\x0a\x07\x6f\x57\x9c\xd1\x5a\xde\xc8\x74\x45\x10\xc6\x57\x56\x69\x56\x60\xfc\xb6\xe1\x82\xe8\xb4\xdd\x46\x0e\x1d\xcd\x64\x81\xb0\xcc\xd7\xb0\x74\xfe\x08\x68\xff\xb0\xdd\x06\x0b\xba\x9a\xc3\x29\xd4\xcc\xa4\x4c\xd0\x33\x49\x93\x04\xbc\x62\xbb\x1d\xe2\x25\xaa\x15\xfc\x0e\x25\xe4\x1c\x45\x66\x08\xb6\xb6\x85\xa6\xae\x51\x77\x47\x9d\xd9\x38\x58\x50\x50\x83\x81\x55\x77\x3c\x8e\x63\x63\x29\xdb\x68\x12\x7e\x1b\x2c\x16\x6d\x7b\x0c\xf7\xdc\x96\x80\x0f\x16\x65\x06\x2b\x2e\x33\x7c\x80\x65\x7c\xa9\x32\x34\xf0\x2a\x82\x90\xce\x86\x64\x2e\x74\x57\xc3\x3e\x95\x63\x0a\x76\xe1\x92\xb0\x55\x2d\x28\xb5\x5a\x73\x69\x73\x08\x33\xce\xa8\x64\xc9\x6f\x26\x51\xdd\x9d\xbe\x44\xe0\x6f\x69\xb4\x8d\x76\x39\x3c\x0c\x0c\xf6\x66\x62\x7f\xa2\x6d\x81\xe2\x71\x4e\x5c\x0f\xd0\xaf\xbe\x65\x1e\xf1\x57\x68\xd5\xd4\x89\xe1\x85\x64\xb6\xd1\xb8\xe3\x39\x49\xe0\xac\x28\x34\x16\x3d\x63\x26\x84\x60\x9d\x82\x58\x66\x2c\xd6\x44\x0c\x57\x77\xb2\x78\x7c\xbd\x19\x89\x91\x8c\x8c\xf8\x5e\x02\x8e\x77\x67\x86\x26\x0d\x83\xda\x60\x93\xa9\x99\x03\x42\xc9\x3f\x28\x0d\x1a\x25\xab\x88\x8a\x4c\x2a\x47\x44\xff\x7f\x7f\xc6\x78\x84\xd2\xc6\x58\x55\x81\x64\x15\x9a\x18\x2e\x94\x06\x7c\x60\x55\x2d\xf0\x4d\x90\x24\x41\x92\x2c\xfe\xa4\x40\xdf\x6e\x3c\xe6\xaf\xd7\x9e\x2a\x27\x51\x4c\xba\x21\xeb\x55\x3f\x72\xb6\xdb\xf8\xcc\x4c\x7f\x5d\x35\x55\x77\x35\x5a\x43\x68\x9a\xea\x3f\xff\x2b\x8c\xd6\xf0\x84\x5b\x27\xb3\x5b\x27\x61\xe4\x1d\x5f\xa5\x4c\xae\x52\xfb\xb0\x86\x17\x77\x11\x05\xea\xf8\x79\x66\x56\xb9\x9c\x43\xb1\x76\x08\xf7\x2c\x9d\xa3\xd4\x06\x8e\xa8\xbe\xbe\x8f\xc0\xce\xcc\x2e\xd3\x0e\xf0\x6c\x3b\xed\x52\xaa\xec\x1a\x96\x54\xec\x0b\xca\x81\x18\xd6\x63\x86\x63\xc3\x4a\xc7\xbc\xae\x65\xe9\xce\xa0\x3a\x48\xcb\x54\x49\x63\x77\x43\x6c\x5b\xe0\x39\x94\xcc\x7c\x99\x07\xd8\xb7\xc1\x81\xf6\xbc\x64\x15\xb1\xdc\x05\x32\xf4\xaa\x9c\x74\xe7\xe3\x0d\xd6\x45\xd0\x77\xd7\x30\x7d\xe4\xee\xf8\x69\x5b\xb8\x6d\x94\xc5\x21\xe7\xfd\x7c\x56\xae\xd8\x3c\x9f\xd6\x71\xbb\xdd\x99\x5f\xf4\x9e\x1c\x9c\x22\x4b\x4b\xdf\x64\xb3\xe9\x45\x01\xac\xf6\x98\xf2\x06\x3c\x4f\x06\x1b\x7b\x08\xf3\x23\xa3\x4d\x42\xf8\xb5\x77\x11\x4e\xdd\x3d\x6d\xc6\x79\x70\x73\x6f\xec\x97\x0d\xba\x24\x81\x4b\x65\x2f\x68\x03\x79\xa7\xb5\x1b\x13\x64\xca\xc0\x7d\x89\x12\xac\xde\xd0\xc4\xb0\x0a\x72\xb4\x69\x09\x0c\x4c\x8d\x29\xcf\x79\x4a\xef\x40\x6e\x37\xc0\x64\x06\xdc\xc2\x3d\x33\x20\x95\xf5\xab\x4c\xbf\xb6\x64\xcc\x32\x5a\x38\xba\x57\xda\xdc\x8f\xb1\xba\x49\x2d\xd5\x50\xb0\x6b\x14\x5d\xad\x03\x1f\x92\x3f\xc2\x69\xee\x54\x28\xad\xe7\x06\x7a\xa1\xb4\xa8\x73\x96\x62\xec\x9b\x7c\x85\x70\x34\xb3\x1c\xf9\xdb\xab\xa8\x33\x49\x2e\xba\xfa\x84\xe3\x48\x79\x03\x21\xbc\x04\x8c\xbd\xf3\x97\x10\x8e\xe1\x87\x5d\x10\xef\x4d\x6f\x77\x28\x0a\x83\x6b\xa5\x04\x32\x09\x5c\x66\x3c\x65\x96\xec\xdf\x97\xe8\x26\xe9\x24\x46\x3a\x39\x96\xc3\x09\xbb\x70\x47\xa3\x2b\xd4\xda\xab\x22\x67\x95\xe2\xe4\x39\x49\xe0\xf4\x14\x24\x77\x82\x3e\xf2\x9c\x09\x83\x04\xdd\xe2\x8e\x69\xd8\x4d\x79\x48\xd0\x99\x33\x34\x3c\x51\xeb\x35\xbc\xc0\xa8\xcb\xe5\x23\x33\x37\x43\x36\x15\x33\x37\x04\x97\xde\x13\xdf\xf4\xe0\x34\x42\x9f\x98\x0f\x71\x9e\x43\x34\x8d\x53\x72\xe1\xa2\x1c\xe3\x09\x06\x92\x5d\x71\x59\x34\x82\xe9\xa7\xf1\xac\x3b\x3c\xe5\x59\xa5\x34\x52\x95\xa9\xff\xd1\x51\xee\x00\xdd\xe6\x1e\x7f\x31\xe3\x66\xc6\x9f\x43\xba\x3e\xd5\x19\xef\x7a\xeb\x3f\x4d\xbd\xb1\x80\xbb\xec\xeb\x4d\x3f\x9b\x80\xb3\x0a\x1c\xe6\xe0\xa5\xb2\x1f\x14\xcb\xf0\xf1\x41\x53\xa0\x75\x19\x64\x04\x35\x1b\x27\x8b\x70\x57\x81\x36\xa4\x12\xe1\x96\x76\xfc\x11\xe8\xa9\xdd\x11\x66\xcc\x0a\x7c\x2e\xca\x13\xcb\x3f\x86\xb1\x73\x4e\x10\xbb\x87\x79\x16\x33\xa4\xbd\x87\x9f\xc6\xb9\xab\xcb\x37\x28\x7b\xb3\xcf\xc6\x78\x92\xff\x61\x84\xcf\x69\xf3\xd0\x8c\x4b\xfb\x28\xc4\xa9\x46\x66\x31\x69\xea\x8c\xde\x53\xd4\xcb\x4a\xfb\xe6\x76\xcd\xee\x37\xe5\x8c\x0c\x4e\x75\xee\xab\x17\xb9\x86\x74\xf0\x62\x20\x67\x5c\x60\x36\x5b\x54\xd7\x70\xc7\x95\xf0\x0b\x83\xca\x7d\xf9\x95\x26\x6b\xfe\xa5\xde\x48\x7e\xdb\xa0\x44\x63\x3a\xfe\xec\x46\x3d\x12\xa8\x32\x45\xcf\x9f\xc5\xbd\x66\xb5\xcf\xfc\xa7\xb8\xb4\xe3\xe4\xa9\x5c\x1a\x73\xed\x52\xed\xe9\x55\x99\x9e\xd3\xff\x48\x17\xda\xbe\x40\x4c\xfc\x55\x33\xf7\xf5\xb6\x8f\xdd\xdf\x84\xe4\x2d\xad\x26\xc3\xbe\x07\x3c\x26\xc5\x40\xda\xef\xc1\xfc\x23\xd4\xdd\x49\xac\xd1\x38\x90\x77\xc7\xfc\xf3\x28\xbc\x63\xec\x00\x87\xdb\x36\x39\x02\x7c\xa8\x59\xff\x56\x04\x62\x88\xa3\x23\x14\x42\x5d\x33\x01\x25\x8a\x1a\xb5\x89\xc1\xfd\xc1\x65\xd8\xd9\xf6\xae\x6c\xde\xc9\xce\xba\xf6\xd8\x26\xbe\x67\x81\x5b\x76\x77\xbe\xf9\x32\xdd\xbf\x24\xba\x20\x7f\xbd\xcb\xee\xf1\xff\x00\x00\x00\xff\xff\x48\xe9\xca\x16\x23\x13\x00\x00") func templateBaseTmplBytes() ([]byte, error) { return bindataRead( @@ -141,7 +141,7 @@ func templateBaseTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/base.tmpl", size: 5127, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/base.tmpl", size: 4899, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -686,7 +686,7 @@ func templateDialectSqlErrorsTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlGlobalsTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x93\x5f\x6b\xdb\x3c\x14\xc6\xaf\xad\x4f\xf1\x34\xf0\x96\xa4\xf8\xb5\xfb\x96\x97\xc1\x3a\x72\xd1\xa5\xd9\x08\x64\x61\x69\xba\xfb\xba\xd2\x71\x22\xaa\x48\x89\x24\xa7\x0e\xc1\xdf\x7d\x48\x76\x4a\x13\xca\xd8\x95\xe1\xfc\x79\xce\xef\x39\x47\x3e\x1c\xf2\x2b\x36\x32\x9b\xbd\x95\xcb\x95\xc7\xcd\xf5\x7f\x9f\xff\xdd\x58\x72\xa4\x3d\xbe\x15\x9c\x9e\x8d\x79\xc1\x44\xf3\x0c\x77\x4a\x21\x16\x39\x84\xbc\xdd\x91\xc8\xd8\xe3\x4a\x3a\x38\x53\x59\x4e\xe0\x46\x10\xa4\x83\x92\x9c\xb4\x23\x81\x4a\x0b\xb2\xf0\x2b\xc2\xdd\xa6\xe0\x2b\xc2\x4d\x76\x7d\xcc\xa2\x34\x95\x16\x4c\xea\x98\x9f\x4e\x46\xe3\xd9\x62\x8c\x52\x2a\x42\x17\xb3\xc6\x78\x08\x69\x89\x7b\x63\xf7\x30\x25\xfc\xbb\x61\xde\x12\x65\xec\x2a\x6f\x1a\xc6\x82\x07\xf0\xca\x79\xb3\xc6\x52\x99\xe7\x42\x39\x14\x5a\x60\x45\x6a\x43\xd6\xa1\x34\x16\x6e\xab\x20\x64\xa1\x88\x7b\x87\xd8\x76\x38\x40\x50\x29\x35\xa1\xd7\x25\x72\xb7\x55\x79\x27\xd0\x43\xd3\xb0\x3c\x87\xd4\x8e\xac\x9f\x16\xce\x4f\xee\x21\xf5\xce\xbc\x90\x8b\x78\x6d\x02\xdb\x8a\x02\x5c\x8b\xec\x6d\xa1\x5d\xc1\xbd\x34\x3a\x02\x58\xf2\x95\xd5\x6d\x7d\x94\x88\x3d\x93\xfb\x8c\x95\x95\xe6\x27\xda\x7d\xee\x6b\x70\xa3\x3d\xd5\x3e\x1b\xb5\xdf\x14\xbe\x3e\x42\x67\x8f\x75\x7a\x9c\x79\xe5\xb6\x2a\x6b\xb5\xbe\x56\x52\x09\xb2\x03\xf4\xa5\xf6\x9f\xfe\x4f\x41\xd6\x1a\x3b\xc0\x81\x25\x91\x2c\x45\x61\x97\x0e\xb7\xc3\xae\x37\x9b\x87\x68\x7f\xc0\x92\x3c\xc7\x4f\xe3\xfc\xd2\xd2\x62\x3e\x85\x30\xe4\xa0\x8d\x87\xab\x36\x1b\x63\xfd\x39\xb2\xe8\x0f\xb0\x26\xbf\x32\x22\x1c\x22\xcc\x7f\x20\x57\x29\x1f\x75\x8c\xc6\xb8\x26\x9e\x46\xcf\x6e\x65\x2a\x25\xf0\x4c\xa0\xda\xdb\x82\x7b\x12\x58\x17\xba\x2a\x94\xda\xa3\x72\x52\x2f\xa3\xf6\xd3\xc3\xf8\xf1\xd7\xc3\x6c\x32\xfb\xfe\x04\xae\x8a\xca\x51\xc6\x12\x59\x1e\x31\xef\x5b\xd7\xfd\x01\x86\xc3\xb7\x15\x74\xbc\x2e\xb8\x4b\xac\x79\x8d\xbe\x2e\x23\x8c\x79\x75\x87\x86\x25\x41\x81\xac\x0d\x71\x5f\x77\x5e\xb9\xaf\x53\xbc\x5b\x46\x8a\xd0\x3a\xf8\x12\x0b\x2f\x86\xd0\x52\x45\xc1\xa4\xbd\x16\xae\xe3\x12\x59\x92\x04\x3d\x41\x25\xd9\xd8\x90\x8d\x94\x71\x14\x36\x17\x86\x5c\xc4\xd0\x8c\xea\x80\x78\xd6\x5d\xae\x7d\x36\x0e\x67\x28\xfb\x3d\x6d\x62\x73\xfb\xda\xe3\x43\x8c\x24\xb7\xf8\x67\xd7\xeb\xa8\x06\xdd\xa8\x5d\x61\x21\x05\xe2\x1d\x4f\x9c\xc4\x51\x0b\x5e\xe8\xfe\xa5\x14\x7f\xc9\xdd\xc5\xa4\x48\x43\x1d\x0b\xb1\x3c\xc7\x8f\xfd\x62\x3e\x4d\xb1\x98\x4f\xa5\xa7\x14\xe4\x79\xc6\xe2\xdc\xb0\xd4\xf7\x47\x3d\x59\x63\xb8\xed\x07\x5b\xbc\xb4\xf4\xc1\x16\xcf\x60\x1a\x96\x04\x86\xa3\x13\x72\xd9\xe9\xa3\x7a\x1b\xf5\x47\x89\x33\x37\xf1\xdf\x25\x2d\xd0\x34\xbf\x03\x00\x00\xff\xff\x4c\x6e\x83\xee\xbf\x04\x00\x00") +var _templateDialectSqlGlobalsTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4c\xcf\x41\x6b\x02\x31\x10\x05\xe0\x7b\x7e\xc5\xc3\xa3\xd0\x5d\xeb\xad\x47\x11\x0b\x42\xe9\xa5\xfd\x03\x6b\xf2\xd6\x0d\x4d\x33\xeb\x4c\xb6\x20\x21\xff\xbd\x28\x16\x7a\x9d\x6f\x66\x1e\xaf\xd6\x7e\xed\xf6\x32\x5f\x35\x9e\xa7\x82\xed\xe6\xf9\xe5\x69\x56\x1a\x73\xc1\xeb\xe0\x79\x12\xf9\xc2\x31\xfb\x0e\xbb\x94\x70\x5f\x32\xdc\x5c\x7f\x18\x3a\xf7\x39\x45\x83\xc9\xa2\x9e\xf0\x12\x88\x68\x48\xd1\x33\x1b\x03\x96\x1c\xa8\x28\x13\xb1\x9b\x07\x3f\x11\xdb\x6e\xf3\xa7\x18\x65\xc9\xc1\xc5\x7c\xf7\xb7\xe3\xfe\xf0\xfe\x71\xc0\x18\x13\xf1\x98\xa9\x48\x41\x88\x4a\x5f\x44\xaf\x90\x11\xe5\x5f\x58\x51\xb2\x73\xeb\xbe\x35\xe7\x6e\x1d\xe0\x17\x2b\xf2\x8d\x73\x92\xd3\x90\x0c\x43\x0e\x98\x98\x66\xaa\x61\x14\x85\x5d\x12\x42\x1c\x12\x7d\x31\xdc\xcf\x6a\x45\xe0\x18\x33\xb1\x7a\x40\x6f\x97\xd4\x3f\x1e\xac\xd0\x5a\xad\x60\x0e\x68\xcd\xfd\x06\x00\x00\xff\xff\xa2\x7b\x06\xae\x26\x01\x00\x00") func templateDialectSqlGlobalsTmplBytes() ([]byte, error) { return bindataRead( @@ -701,7 +701,7 @@ func templateDialectSqlGlobalsTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/globals.tmpl", size: 1215, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/dialect/sql/globals.tmpl", size: 294, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/base.tmpl b/entc/gen/template/base.tmpl index 3791ab5db..fc4973e57 100644 --- a/entc/gen/template/base.tmpl +++ b/entc/gen/template/base.tmpl @@ -174,13 +174,4 @@ func IsConstraintError(err error) bool { {{ xtemplate $tmpl $ }} {{ end }} -{{ $id := (index $.Nodes 0).ID.Type }} -// keys returns the keys/ids from the edge map. -func keys(m map[{{ $id }}]struct{}) []{{ $id }} { - s := make([]{{ $id }}, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} {{ end }} diff --git a/entc/gen/template/dialect/sql/globals.tmpl b/entc/gen/template/dialect/sql/globals.tmpl index ec63b33c3..66e8f9139 100644 --- a/entc/gen/template/dialect/sql/globals.tmpl +++ b/entc/gen/template/dialect/sql/globals.tmpl @@ -5,36 +5,4 @@ in the LICENSE file in the root directory of this source tree. */}} {{/* custom globals and helpers for sql dialects */}} -{{ define "dialect/sql/globals" }} -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} -{{ end }} \ No newline at end of file +{{ define "dialect/sql/globals" }}{{ end }} diff --git a/entc/integration/config/ent/ent.go b/entc/integration/config/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/entc/integration/config/ent/ent.go +++ b/entc/integration/config/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/customid/ent/ent.go b/entc/integration/customid/ent/ent.go index 1cbaafd53..8deb663ea 100644 --- a/entc/integration/customid/ent/ent.go +++ b/entc/integration/customid/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -16,7 +15,6 @@ import ( "github.com/facebookincubator/ent/dialect" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/dialect/sql/sqlgraph" - "github.com/google/uuid" ) // ent aliases to avoid import conflict in user's code. @@ -225,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[uuid.UUID]struct{}) []uuid.UUID { - s := make([]uuid.UUID, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/ent/ent.go b/entc/integration/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/entc/integration/ent/ent.go +++ b/entc/integration/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/gremlin/ent/ent.go b/entc/integration/gremlin/ent/ent.go index fc706ef2f..0b0c6501b 100644 --- a/entc/integration/gremlin/ent/ent.go +++ b/entc/integration/gremlin/ent/ent.go @@ -282,12 +282,3 @@ func isConstantError(r *gremlin.Response) (*ConstraintError, bool) { } return e, true } - -// keys returns the keys/ids from the edge map. -func keys(m map[string]struct{}) []string { - s := make([]string, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/hooks/ent/ent.go b/entc/integration/hooks/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/entc/integration/hooks/ent/ent.go +++ b/entc/integration/hooks/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/idtype/ent/ent.go b/entc/integration/idtype/ent/ent.go index 104d4e151..8deb663ea 100644 --- a/entc/integration/idtype/ent/ent.go +++ b/entc/integration/idtype/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[uint64]struct{}) []uint64 { - s := make([]uint64, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/json/ent/ent.go b/entc/integration/json/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/entc/integration/json/ent/ent.go +++ b/entc/integration/json/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/migrate/entv1/ent.go b/entc/integration/migrate/entv1/ent.go index 4502fa3c6..04caeffa5 100644 --- a/entc/integration/migrate/entv1/ent.go +++ b/entc/integration/migrate/entv1/ent.go @@ -7,7 +7,6 @@ package entv1 import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/migrate/entv2/ent.go b/entc/integration/migrate/entv2/ent.go index a8e4ca189..24a468219 100644 --- a/entc/integration/migrate/entv2/ent.go +++ b/entc/integration/migrate/entv2/ent.go @@ -7,7 +7,6 @@ package entv2 import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/privacy/ent/ent.go b/entc/integration/privacy/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/entc/integration/privacy/ent/ent.go +++ b/entc/integration/privacy/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/entc/integration/template/ent/ent.go b/entc/integration/template/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/entc/integration/template/ent/ent.go +++ b/entc/integration/template/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/edgeindex/ent/ent.go b/examples/edgeindex/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/edgeindex/ent/ent.go +++ b/examples/edgeindex/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/entcpkg/ent/ent.go b/examples/entcpkg/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/entcpkg/ent/ent.go +++ b/examples/entcpkg/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/m2m2types/ent/ent.go b/examples/m2m2types/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/m2m2types/ent/ent.go +++ b/examples/m2m2types/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/m2mbidi/ent/ent.go b/examples/m2mbidi/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/m2mbidi/ent/ent.go +++ b/examples/m2mbidi/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/m2mrecur/ent/ent.go b/examples/m2mrecur/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/m2mrecur/ent/ent.go +++ b/examples/m2mrecur/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/o2m2types/ent/ent.go b/examples/o2m2types/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/o2m2types/ent/ent.go +++ b/examples/o2m2types/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/o2mrecur/ent/ent.go b/examples/o2mrecur/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/o2mrecur/ent/ent.go +++ b/examples/o2mrecur/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/o2o2types/ent/ent.go b/examples/o2o2types/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/o2o2types/ent/ent.go +++ b/examples/o2o2types/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/o2obidi/ent/ent.go b/examples/o2obidi/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/o2obidi/ent/ent.go +++ b/examples/o2obidi/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/o2orecur/ent/ent.go b/examples/o2orecur/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/o2orecur/ent/ent.go +++ b/examples/o2orecur/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/start/ent/ent.go b/examples/start/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/start/ent/ent.go +++ b/examples/start/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -} diff --git a/examples/traversal/ent/ent.go b/examples/traversal/ent/ent.go index d28ff7d7b..8deb663ea 100644 --- a/examples/traversal/ent/ent.go +++ b/examples/traversal/ent/ent.go @@ -7,7 +7,6 @@ package ent import ( - "context" "errors" "fmt" "strings" @@ -224,44 +223,3 @@ func rollback(tx dialect.Tx, err error) error { } return err } - -// insertLastID invokes the insert query on the transaction and returns the LastInsertID. -func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) (int64, error) { - query, args := insert.Query() - // PostgreSQL does not support the LastInsertId() method of sql.Result - // on Exec, and should be extracted manually using the `RETURNING` clause. - if insert.Dialect() == dialect.Postgres { - rows := &sql.Rows{} - if err := tx.Query(ctx, query, args, rows); err != nil { - return 0, err - } - defer rows.Close() - if !rows.Next() { - return 0, fmt.Errorf("no rows found for query: %v", query) - } - var id int64 - if err := rows.Scan(&id); err != nil { - return 0, err - } - return id, nil - } - // MySQL, SQLite, etc. - var res sql.Result - if err := tx.Exec(ctx, query, args, &res); err != nil { - return 0, err - } - id, err := res.LastInsertId() - if err != nil { - return 0, err - } - return id, nil -} - -// keys returns the keys/ids from the edge map. -func keys(m map[int]struct{}) []int { - s := make([]int, 0, len(m)) - for id := range m { - s = append(s, id) - } - return s -}