Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert entire row with a specifc datatype #344

Open
MangoIV opened this issue Sep 3, 2023 · 14 comments
Open

insert entire row with a specifc datatype #344

MangoIV opened this issue Sep 3, 2023 · 14 comments
Labels

Comments

@MangoIV
Copy link
Collaborator

MangoIV commented Sep 3, 2023

Is there an intented way to express this generically?
image

In my case the names are exactly like the ones specified with the overloaded labels so it should be possible to just get the values from the types in the input type?

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

I guess it's a bit more complicated because you'd have to carry along the labels split from the input type in a wrapper around Manipulation

@echatav
Copy link
Contributor

echatav commented Sep 3, 2023

I've tried at times to make a params term that could be used in this type of situation but I never found a way to get it to work right to figure out the induction on type level natural numbers. For inlining there's inlineColumns which might be used for similar purposes.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

I don’t think going via the numbers is a good idea tbh. I don’t have a solution written out though so I can be wrong

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

Thank you for writing this library. It’s awesome. Compile times are of course ass (21s spent in the simplifier) but that’s just GHCs fault.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

image (this is actually hilarious)

@echatav
Copy link
Contributor

echatav commented Sep 3, 2023

class All KnownNat ixs
  => HasParams (ixs :: [Nat]) (params :: [NullType]) (tys :: [NullType]) where
    parameters :: NP (TypeExpression db) tys -> NP (Expression grp lat with db from) tys
instance HasParams '[] params '[] where
  parameters Nil = Nil
instance (HasParam ix params ty, HasParams ixs params tys)
  => HasParams (ix:ixs) params (ty:tys) where
    parameters (ty :* tys) = parameter @ix @params ty :* parameters @ixs @params tys
    
params
  :: forall ns tys lat with db params from grp
   . (All (NullTyped db) tys, HasParameters ns params tys)
  => NP (Expression grp lat with db params from) tys
params = parameters @ns (hcpure (Proxy @(NullTyped db)) (nulltype @db))

Maybe we can do something built on this? Haven't checked it.

@echatav
Copy link
Contributor

echatav commented Sep 3, 2023

(Values_ (hmap ((`as` Alias) . Set) (params @'[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])))

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

what I'm trying to say is can we just have something like GManipulation which instead of taking a list of NullType takes a list of NullType paired with their original name (as computed with the squeals rowtype type family) and then wrap around a Manipulation and then we can avoid the whole natural numbers stuff altogether?

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

so similarly to the Manipulation_ type family but it doesn't throw away the label types in the parameter list of NullType passed to Manipulation Sorry if that's a bit unclear, I haven't dug in too deep yet :D

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 3, 2023

thank you for your support!

@echatav
Copy link
Contributor

echatav commented Sep 4, 2023

Oh those label types aren't thrown away.

In my case the names are exactly like the ones specified with the overloaded labels so it should be possible to just get the values from the types in the input type?

Sure, you don't need to include the labels, #label is just short for Alias @label and the label can be inferred by GHC so you can just use Alias if you want, i.e. Set (param @1) `as` Alias :* Set (param @2) `as` Alias :* ...

The kind of the last type parameter of a QueryClause is a ColumnsType so includes column labels as well as optionalities (default value or not) in addition to NullTypes.

@echatav
Copy link
Contributor

echatav commented Sep 4, 2023

We cannot avoid natural numbers because these actually correspond to PostgreSQL positional parameter numbers.

@MangoIV
Copy link
Collaborator Author

MangoIV commented Sep 4, 2023

Ah right that makes sense. Unfortunate. Well then we have to hack the natural numbers into place i guess

@mwotton
Copy link
Contributor

mwotton commented Sep 17, 2023

@MangoIV something I've done in my last workplace was to aggressively use schemas and multiple Schema.hs files to cut down on squeal compile times, might be worth a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants