mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
feat: Make sql_type an enum property in the Ifc2Sql recipe
Since there is a limited number of choices, a string property wouldn't be very helpful. Use a dynamic enum property (which is adjusted according to which types of SQL are available) instead.
This commit is contained in:
committed by
Dion Moult
parent
a7152bdef0
commit
82a6ddb01c
@@ -22,6 +22,7 @@ import re
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import typing
|
||||||
import itertools
|
import itertools
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
@@ -33,15 +34,19 @@ import ifcopenshell.util.schema
|
|||||||
import ifcopenshell.util.attribute
|
import ifcopenshell.util.attribute
|
||||||
import ifcopenshell.util.placement
|
import ifcopenshell.util.placement
|
||||||
|
|
||||||
|
SQLTypes = typing.Literal["SQLite", "MySQL"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlite3
|
import sqlite3
|
||||||
except:
|
except:
|
||||||
print("No SQLite support")
|
print("No SQLite support")
|
||||||
|
SQLTypes = typing.Literal["MySQL"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
except:
|
except:
|
||||||
print("No MySQL support")
|
print("No MySQL support")
|
||||||
|
SQLTypes = typing.Literal["SQLite"]
|
||||||
|
|
||||||
|
|
||||||
class Patcher:
|
class Patcher:
|
||||||
@@ -50,7 +55,7 @@ class Patcher:
|
|||||||
src,
|
src,
|
||||||
file,
|
file,
|
||||||
logger,
|
logger,
|
||||||
sql_type: str = "sqlite",
|
sql_type: SQLTypes = "SQLite",
|
||||||
host: str = "localhost",
|
host: str = "localhost",
|
||||||
username: str = "root",
|
username: str = "root",
|
||||||
password: str = "pass",
|
password: str = "pass",
|
||||||
@@ -79,8 +84,8 @@ class Patcher:
|
|||||||
IfcRepresentation and IfcRepresentationItem classes. These tables are
|
IfcRepresentation and IfcRepresentationItem classes. These tables are
|
||||||
unnecessary if you are not interested in geometry.
|
unnecessary if you are not interested in geometry.
|
||||||
|
|
||||||
:param sql_type: Choose between "sqlite" or "mysql"
|
:param sql_type: Choose between "SQLite" or "MySQL"
|
||||||
:type sql_type: str
|
:type sql_type: typing.Literal["SQLite", "MySQL"]
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
@@ -92,7 +97,7 @@ class Patcher:
|
|||||||
self.src = src
|
self.src = src
|
||||||
self.file = file
|
self.file = file
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.sql_type = sql_type
|
self.sql_type = sql_type.lower()
|
||||||
self.host = host
|
self.host = host
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|||||||
Reference in New Issue
Block a user