<commit_before>﻿using System;
using System.Data.SqlClient;
using System.Linq;

using CaptainData.Schema;

namespace CaptainData
{
    public class Captain
    {
        private readonly SqlConnection _sqlConnection;
        private readonly Context _context;

        public Captain(SqlConnection sqlConnection)
        {
            _sqlConnection = sqlConnection;

            var schemaInformation = SchemaInformation.Create(sqlConnection);
            _context = new Context(schemaInformation);
        }

        public Captain Insert(string tableName, object overrides)
        {
            var overridesDictionary = overrides.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(overrides, null));
            var instruction = new Instruction { TableName = tableName };
            var columns = _context.SchemaInformation[tableName];

            foreach (var column in columns)
            {
                if (overridesDictionary.ContainsKey(column.ColumnName))
                {
                    instruction[column.ColumnName] = overridesDictionary[column.ColumnName];
                }
                else
                {
                    ApplyDefaults(instruction, column);
                }
            }

            _context.AddInstruction(instruction);
            return this;
        }

        private void ApplyDefaults(Instruction instruction, ColumnSchema column)
        {
            if (column.IsIdentity)
            {
                return;
            }

            if (column.IsNullable)
            {
                instruction[column.ColumnName] = null;
            }
            else
            {
                switch (column.DataType)
                {
                    case SqlDataType.Int:
                        instruction[column.ColumnName] = 0;
                        break;
                    case SqlDataType.Nvarchar:
                        instruction[column.ColumnName] = string.Empty;
                        break;
                    case SqlDataType.Unknown:
                        throw new ArgumentException();
                    default:
                        throw new NotImplementedException();
                }
            }
        }

        public void Go()
        {
            _context.Apply(_sqlConnection);
        }
    }
}

    
<commit_msg>overrides should be optional of course<commit_after>﻿using System;
using System.Data.SqlClient;
using System.Linq;

using CaptainData.Schema;

namespace CaptainData
{
    public class Captain
    {
        private readonly SqlConnection _sqlConnection;
        private readonly Context _context;

        public Captain(SqlConnection sqlConnection)
        {
            _sqlConnection = sqlConnection;

            var schemaInformation = SchemaInformation.Create(sqlConnection);
            _context = new Context(schemaInformation);
        }

        public Captain Insert(string tableName, object overrides = null)
        {
            var overridesDictionary = overrides?.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(overrides, null));
            var instruction = new Instruction { TableName = tableName };
            var columns = _context.SchemaInformation[tableName];

            foreach (var column in columns)
            {
                if (overridesDictionary?.ContainsKey(column.ColumnName) ?? false)
                {
                    instruction[column.ColumnName] = overridesDictionary[column.ColumnName];
                }
                else
                {
                    ApplyDefaults(instruction, column);
                }
            }

            _context.AddInstruction(instruction);
            return this;
        }

        private void ApplyDefaults(Instruction instruction, ColumnSchema column)
        {
            if (column.IsIdentity)
            {
                return;
            }

            if (column.IsNullable)
            {
                instruction[column.ColumnName] = null;
            }
            else
            {
                switch (column.DataType)
                {
                    case SqlDataType.Int:
                        instruction[column.ColumnName] = 0;
                        break;
                    case SqlDataType.Nvarchar:
                        instruction[column.ColumnName] = string.Empty;
                        break;
                    case SqlDataType.Unknown:
                        throw new ArgumentException();
                    default:
                        throw new NotImplementedException();
                }
            }
        }

        public void Go()
        {
            _context.Apply(_sqlConnection);
        }
    }
}

    

{'fraction_non_alphanumeric': 0.06933614330874605, 'fraction_numerical': 0.00042149631190727084, 'mean_word_length': 1.3425468904244817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2117035', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1014, 'n_words': 223}