GithubHelp home page GithubHelp logo

sqlmodeller's People

Contributors

advertisingstudio avatar jmenziessmith avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sqlmodeller's Issues

Custom colum selector - not easy to do

First, let me say this is the most promising SQL builder for .NET I have seen so far!
It seems to have the right amount of support for programmatically creating SQL statements while still giving the developer control over the output.

Here is my issue:
I would like to add the following class and extensions, but the library does not make it easy to extend it, as the class is not picked up by the query compiler and no new IColumnSelectorCompiler can be registered.

public class PlainColumnSelector: SqlColumnSelector, IColumnSelector
{
    public PlainColumnSelector(Table table, string fieldName) : base(FullName(table.Alias, fieldName)) { }

    static string FullName(string tableAlias, string fieldName) {
        if (string.IsNullOrWhiteSpace(tableAlias)) {
            return fieldName;
        }
        return string.Format("{0}.{1}", tableAlias, fieldName);
    }
}

public static class Extensions
{
    public static SelectQuery Select(this SelectQuery query, Table table, string field) {
        query.SelectColumns.Add(new PlainColumnSelector(table, field));
        return query;
    }
}

SELECT DISTINCT?

Does not seem to be directly supported. Is there a workaround?

WhereColumnValue, WhereColumnIn do not quote strings when parameters are not used

Test case should return ...IN ('Jorge' ,'Benito' ,'Juan' ), but returns IN (Jorge ,Benito ,Juan )

        public void WhereColumnIn() {
            var teamTable = new Table("t", "Team");
            var names = new List<string> { "Jorge", "Benito", "Juan" };
            var select = new SelectQuery()
                .From(teamTable)
                .Select(teamTable, "Name", "T_NAME")
                .WhereColumnIn(teamTable.Alias, "Name", names, DbType.AnsiString);
            var query = new Query();
            query.SelectQuery = select;
            var compiled = query.Compile(false);  // NOTE: useParameters = false

            Console.WriteLine(compiled.Sql);
        }

This could break code that uses parameter literals as values, but the following change would fix the test case:

    public class NoQueryParameterManager : IQueryParameterManager
    {
        
        public string Parameterize(string value, DbType type, string alias = null)
        {
            // return value; 
            return ToStringHelper.ValueString(value, type);
        }
    }

Now, with this fix applied, if one passes a string that one does not want to quote, as in @name, then one would have to use a DbType other than string or DateTime, probably best: DbType.Object, as in:

        public void WhereColumnValue() {
            var teamTable = new Table("t", "Team");
            var select = new SelectQuery()
                .From(teamTable)
                .Select(teamTable, "Name", "T_NAME")
                .WhereColumnValue(teamTable.Alias, "Name", Compare.Equal, "Jorge")
                .WhereColumnValue(teamTable.Alias, "Name", Compare.Equal, "@Name", DbType.Object);
            var query = new Query();
            query.SelectQuery = select;
            var compiled = query.Compile(false);

            Console.WriteLine(compiled.Sql);
        }

Karl

Visual Studio 2017 - netstandard compatibility

Not really an issue, but:

I needed to use SqlModeller in a netstandard based project running in VS 2017 and converted the solution over to the new project model. You may have a look at the netstandard1.2 branch of my fork: https://github.com/kwaclaw/SqlModeller . (Note: I did not change the version number).

Among the changes made:

  • I had to make minor changes in CompilerRegistry.cs, due to differences in reflection classes.
  • There were a few code files not used in the old project, but still part of the repository. I removed them to exclude them from the build (simpler than adding exclusion rules to the project file).
  • nuspec was absorbed into the project file.
  • nuget-create.bat had to be changed.
  • The test project had to be modified as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.