question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to generate the list of tables?

See original GitHub issue

Maintaining the list of Tables is a bit tedious.

When a table is removed it is easy to update the list because there is a compiler error.

However, when adding a table the compiler doesn’t provide any help. Would it be possible to add support for generating the list of tables?

The things that would need to be configurable are the output and the namespace (could be inherited from the general.namespace.

In my project we generate it using this convention:

namespace Antidote.Database

[<RequireQualifiedAccess>]
module Tables =

    open SqlHydra.Query

    let acsIdentities = table<dbo.AcsIdentities> |> inSchema (nameof dbo)
    let acsTokens = table<dbo.AcsTokens> |> inSchema (nameof dbo)
    let callQueueEntries = table<dbo.CallQueueEntries> |> inSchema (nameof dbo)

    let callRatingImprovementsByCallRating =
        table<dbo.CallRatingImprovementsByCallRating> |> inSchema (nameof dbo)

    let callRatings = table<dbo.CallRatings> |> inSchema (nameof dbo)

Having Tables marked as RequireQualifiedAccess makes the consumer experience easy.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:29 (29 by maintainers)

github_iconTop GitHub Comments

1reaction
JordanMarrcommented, Dec 18, 2022

The Readers change has been made and is checked into the main branch.

1reaction
JordanMarrcommented, Dec 17, 2022

I believe that the “table valued functions” will need to have their return types generated. They will live directly within the schema, alongside the table records. However, that should be fine since we will have Tables and Functions modules.

I asked this question with a specific situation in mind. I suppose the name of the function record will come from the function name.

There will need to be a function very similar to the table function that will return a QuerySource<'T>, where 'T is the table valued function’s return type. I would call it function, but that is a reserved keyword, so it will have to be something else. So if the table valued function’s name is udfGetOrders that takes an ‘int’ as input, the generated code might look like this:

module dbo = 
    type udfGetOrders = { OrderId: int; Total: decimal } // the generated function return type

    module Functions = 
        // Partially applied, takes an `int`, returns a `QuerySource<udfGetOrders>`
        let udfGetOrders = SqlHydra.Query.Function.udf<int, udfGetOrders> 
    let udf<'Input, 'Output> (input: 'Input) = 
        let ent = typeof<'Output>
        let tables = Map [Root, { Name = ent.Name; Schema = ent.DeclaringType.Name}]
        QuerySource<'Output>(tables)

Usage:

select {
    for o in dbo.Functions.udfGetOrders 123 do
    select o
}

Is it possible to have a Table and a Function sharing the same name? If yes, how will the conflict of name be resolved?

My assumption was that SQL Server should disallow naming a function with the same name as an existing table. I just tried it and verified that it does throw an error:

image

I’m not particularly concerned with the way the generated code looks since it hidden from view by default. However, I am not against reworking to make them hidden from Intellisense.

I am not particularly concerned neither but if we are doing some clean up why not taking that chance too 😃

Agreed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Two ways to generate a list of tables in a Word document
By giving your tables captions, you can easily generate a list of tables (and figures). The captions serve as descriptive titles, ...
Read more >
How to Create and Update a List of Tables or ... - YouTube
Learn how to create and update a list of tables or list of figures in Microsoft Word. Note that Word calls a list...
Read more >
How to insert a list of tables or figures in Word - YouTube
This video will show you how to automatically create a list of tables or figures for your research report, dissertation or thesis.
Read more >
How to Create and Update a List of Tables or Figures in ...
Learn how to create and update a list of tables or figures in Microsoft Word. Note that Word calls a list of tables...
Read more >
How to create Table of Figures and List of Tables
Update a List of Tables or Figures · On the References tab, in the Captions group, click the Update Table button: Update Table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found