Last active
April 28, 2020 17:26
-
-
Save anytizer/205242a79e196e5766cc5d4da3e92bcc to your computer and use it in GitHub Desktop.
Convert SQLite database into Data Transfer Object for C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
database = r"d:\Desktop\database\employees\employees.db" | |
connection = sqlite3.connect(database) | |
print("namespace dtos {") | |
tables_sql = "SELECT name FROM sqlite_master WHERE type='table';"; | |
for table in connection.execute(tables_sql).fetchall(): | |
cursor = connection.execute("pragma table_info(`{0}`);".format(table[0])) | |
columns = cursor.fetchall() | |
print(" public class {0}DTO {{".format(table[0].title())) | |
for col in columns: | |
print(" public string {0} {{ get; set; }}".format(col[1])) | |
print(f" }}") | |
print("}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace dtos { | |
public class EmployeesDTO { | |
public string employee_id { get; set; } | |
public string employee_code { get; set; } | |
public string employee_title { get; set; } | |
public string employee_name { get; set; } | |
public string employee_email { get; set; } | |
public string employee_phone { get; set; } | |
public string employee_address { get; set; } | |
public string is_visible { get; set; } | |
} | |
public class ChatsDTO { | |
public string chat_id { get; set; } | |
public string chat_on { get; set; } | |
public string chat_sender { get; set; } | |
public string chat_message { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment