<commit_before>#!/usr/bin/python
#
# Generate C++ structs for the tables.

import os
import sys
import psycopg2
import argparse

# Generate a argument parser
parser = argparse.ArgumentParser(description='Create C++ structs from a database table structure.')
parser.add_argument('-u', '--user', dest='user', required=True, help='PostgreSQL user')
parser.add_argument('--host', dest='host', required=True, help='PostgreSQL host')
parser.add_argument('-p', '--password', dest='password', required=True, help='PostgreSQL password')
parser.add_argument('-d', '--dbname', dest='dbname', required=True, help='PostgreSQL database')
parser.add_argument('-o', '--output-dir', dest='outputdir', help='Output directory', default='tables/')
parser.add_argument('-n', '--namespace', dest='namespace', help='C++ namespace', default='model')
args = parser.parse_args()

def _writeLine(fd, indent, line):
    fd.write(("\t" * indent) + line + "\n")

def _getIncludeGuard(namespace, table):
    return namespace.upper() + "_" + table.upper() + "_H"

# SQL types
types = {
    'tinyint': 'tinyint',
    'smallint': 'smallint',
    'integer': 'integer',
    'int': 'integer',
    'bigint': 'bigint',
    'char': 'char_',
    'varchar': 'varchar',
    'character varying': 'varchar',
    'text': 'text',
    'bool': 'boolean',
    'double': 'floating_point',
    'float': 'floating_point',
    'numeric': 'floating_point',

    # For now keep this a varchar
    'date': 'varchar',
    'time without time zone': 'varchar',
    'timestamp without time zone': 'varchar',<commit_msg>Add boolean value and 'USER-DEFINED' types<commit_after>#!/usr/bin/python
#
# Generate C++ structs for the tables.

import os
import sys
import psycopg2
import argparse

# Generate a argument parser
parser = argparse.ArgumentParser(description='Create C++ structs from a database table structure.')
parser.add_argument('-u', '--user', dest='user', required=True, help='PostgreSQL user')
parser.add_argument('--host', dest='host', required=True, help='PostgreSQL host')
parser.add_argument('-p', '--password', dest='password', required=True, help='PostgreSQL password')
parser.add_argument('-d', '--dbname', dest='dbname', required=True, help='PostgreSQL database')
parser.add_argument('-o', '--output-dir', dest='outputdir', help='Output directory', default='tables/')
parser.add_argument('-n', '--namespace', dest='namespace', help='C++ namespace', default='model')
args = parser.parse_args()

def _writeLine(fd, indent, line):
    fd.write(("\t" * indent) + line + "\n")

def _getIncludeGuard(namespace, table):
    return namespace.upper() + "_" + table.upper() + "_H"

# SQL types
types = {
    'tinyint': 'tinyint',
    'smallint': 'smallint',
    'integer': 'integer',
    'int': 'integer',
    'bigint': 'bigint',
    'char': 'char_',
    'varchar': 'varchar',
    'character varying': 'varchar',
    'text': 'text',
    'bool': 'boolean',
    'boolean': 'boolean',
    'double': 'floating_point',
    'float': 'floating_point',
    'numeric': 'floating_point',

    # For now keep this a varchar
    'date': 'varchar',
    'time without time zone': 'varchar',
    'timestamp without time zone': 'varchar',

    # User defined types, for now a varchar
    'USER-DEFINED': 'varchar',
{'fraction_non_alphanumeric': 0.1866338158299969, 'fraction_numerical': 0.0006159531875577456, 'mean_word_length': 4.831238779174147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1955990', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1046, 'n_words': 271}