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.

Analyzer doesn't seem to detect referenced literal queries in nested modules in fsx files

See original GitHub issue

Describe the bug I followed the setup for the analyzer in ionide, windows 10 and net5, but I cannot make it work…

if i change the db name the analyzer complains, so he is alive (?) but he cannot check issues with db columns… image

docker run --name localdb -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres

in postgres i then run this

CREATE SCHEMA test;

CREATE TABLE test.articles (
    id BIGINT PRIMARY KEY NOT NULL, --could be string to be extensible
    art_name CITEXT UNIQUE NOT NULL, --creates unique index
    stock BIGINT NOT NULL
);

i installed pgsql analyzer (see sql errors at edit time) at root of where the .fsx file is

dotnet tool install --global Paket
paket init
paket add NpgsqlFSharpAnalyzer --group Analyzers

and the NPGSQL_FSHARP file (which seems to work as wrong connection triggers)

Host=localhost; Username=postgres; Password=password; Database=postgres

i also tried to run Ubik on the file, but it reports no error, while the column name x does not exist in practice.

To Reproduce

#r "nuget:Npgsql.FSharp"
#r "nuget:FSharp.Data"

open FSharp.Data
open FSharp.Core

module Constants =

    [<Literal>]
    let sqlDevConnection = "Host=localhost;Database=postgres;Username=postgres;Password=password"


//sensitive data should be injected from environment
System.Environment.SetEnvironmentVariable("DATABASE_CONNECTION_STRING", Constants.sqlDevConnection)


module Domain =
    type Article = { 
            Id : int ; 
            Name: string; 
            Stock: int 
        } 

module Data =
    open ProvidedTypes
    open Domain
    open Npgsql.FSharp

    module Queries =

        [<Literal>]
        let getArticles =
            "SELECT x \n\
            FROM test.articles"

    let getConnectionString () =
        System.Environment.GetEnvironmentVariable "DATABASE_CONNECTION_STRING"

    let getArticles () =
        getConnectionString()
        |> Sql.connect
        |> Sql.query Queries.getArticles
        |> Sql.execute (fun read ->
            {
                Id = read.int "id"
                Name = read.text "art_name"
                Stock = read.int "stock"
            })

Expected behavior Should underline the non existing column X and give a warning

Screenshots

image

image

image

Desktop (please complete the following information):

  • OS: Windows 10 also tried WSL ubuntu
  • NET5 sdk

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Zaid-Ajajcommented, Jun 5, 2021

Hi there @jkone27 thanks for filing the issue. My initial thoughts is that the analyser isn’t able to detect the referenced query using the fully qualified name Queries.getArticles. can you try just getArticles without the full module? Or simply use an inline query string to see If that fixes the issue?

I will give this a try later and will let you know how it goes

1reaction
Zaid-Ajajcommented, Jun 6, 2021

Since this is quite difficult to implement, it is easier to just not use nested modules in fsx queries and to keep things simple

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · Zaid-Ajaj/Npgsql.FSharp.Analyzer
F# analyzer that provides embedded SQL syntax analysis, type-checking for ... Analyzer doesn't seem to detect referenced literal queries in nested modules ......
Read more >
The Problem with F# Evangelism
I recently wrote a C# report integration service - it was a C# service that connected to a DB at specific time intervals,...
Read more >
The F# 4.1 Language Specification
Note: thi does not yet incorporate the RFCs for F# 4.1, see ... syntax is the default for all F# code in files...
Read more >
GCHP - Release 14.1.1 GEOS-Chem Support Team
The GCHP repository has submodules (other repositories that are nested inside the GCHP repository) that aren't.
Read more >
Untitled
Isiticili kirpik kivirici, Fadas da barbie, Crayola mini-twistables crayons 10pk, Anchetatorul colecteaza, String literal does not match?
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