@@ -32,7 +32,7 @@ def interactive_create_table(workdir: Path):
3232 """Create a table interactively by asking user for table name, columns, etc."""
3333 try :
3434 tables = FileSystemJsonLTables (workdir = workdir )
35-
35+
3636 # Get table name
3737 print ("Creating a new table..." )
3838 while True :
@@ -44,49 +44,65 @@ def interactive_create_table(workdir: Path):
4444 # Check if table already exists
4545 existing_table = tables .get_table (table_name )
4646 if existing_table :
47- print (f"Table '{ table_name } ' already exists. Please choose a different name." )
47+ print (
48+ f"Table '{ table_name } ' already exists. Please choose a different name."
49+ )
4850 continue
4951 break
5052 except FileNotFoundError :
5153 # Table doesn't exist, which is what we want
5254 break
53-
55+
5456 # Get columns
5557 columns = []
5658 print (f"\n Now let's add columns to the '{ table_name } ' table." )
5759 print ("Available column types: int, string, float, bool" )
5860 print ("Press Enter with empty column name to finish adding columns.\n " )
59-
61+
6062 while True :
6163 column_name = input ("Column name: " ).strip ()
6264 if not column_name :
6365 if len (columns ) == 0 :
6466 print ("At least one column is required. Please add a column." )
6567 continue
6668 break
67-
69+
6870 # Check if column name already exists
6971 if any (col .name == column_name for col in columns ):
70- print (f"Column '{ column_name } ' already exists. Please choose a different name." )
72+ print (
73+ f"Column '{ column_name } ' already exists. Please choose a different name."
74+ )
7175 continue
72-
76+
7377 # Get column type
7478 while True :
75- column_type_str = input (f"Column type for '{ column_name } ' (int/string/float/bool): " ).strip ().lower ()
79+ column_type_str = (
80+ input (f"Column type for '{ column_name } ' (int/string/float/bool): " )
81+ .strip ()
82+ .lower ()
83+ )
7684 if column_type_str in ["int" , "string" , "float" , "bool" ]:
7785 column_type = ColumnType (column_type_str )
7886 break
7987 else :
80- print ("Invalid column type. Please enter: int, string, float, or bool" )
81-
88+ print (
89+ "Invalid column type. Please enter: int, string, float, or bool"
90+ )
91+
8292 # Ask if it's a primary key
83- is_primary = input (f"Is '{ column_name } ' a primary key? (y/N): " ).strip ().lower ()
84- is_primary_key = is_primary in ['y' , 'yes' ]
85-
93+ is_primary = (
94+ input (f"Is '{ column_name } ' a primary key? (y/N): " ).strip ().lower ()
95+ )
96+ is_primary_key = is_primary in ["y" , "yes" ]
97+
8698 # Ask for default value
8799 default_value = None
88- has_default = input (f"Does '{ column_name } ' have a default value? (y/N): " ).strip ().lower ()
89- if has_default in ['y' , 'yes' ]:
100+ has_default = (
101+ input (f"Does '{ column_name } ' have a default value? (y/N): " )
102+ .strip ()
103+ .lower ()
104+ )
105+ if has_default in ["y" , "yes" ]:
90106 while True :
91107 default_str = input (f"Default value for '{ column_name } ': " ).strip ()
92108 try :
@@ -96,41 +112,45 @@ def interactive_create_table(workdir: Path):
96112 elif column_type == ColumnType .float :
97113 default_value = float (default_str ) if default_str else None
98114 elif column_type == ColumnType .bool :
99- if default_str .lower () in [' true' , '1' , ' yes' , 'y' ]:
115+ if default_str .lower () in [" true" , "1" , " yes" , "y" ]:
100116 default_value = True
101- elif default_str .lower () in [' false' , '0' , 'no' , 'n' ]:
117+ elif default_str .lower () in [" false" , "0" , "no" , "n" ]:
102118 default_value = False
103- elif default_str == '' :
119+ elif default_str == "" :
104120 default_value = None
105121 else :
106122 raise ValueError ("Invalid boolean value" )
107123 else : # string
108124 default_value = default_str if default_str else None
109125 break
110126 except ValueError :
111- print (f"Invalid default value for { column_type .value } type. Please try again." )
112-
127+ print (
128+ f"Invalid default value for { column_type .value } type. Please try again."
129+ )
130+
113131 # Create column
114132 column = Column (
115133 name = column_name ,
116134 type = column_type ,
117135 is_primary_key = is_primary_key ,
118- default = default_value
136+ default = default_value ,
119137 )
120138 columns .append (column )
121139 print (f"✓ Added column '{ column_name } ' ({ column_type .value } )" )
122-
140+
123141 # Create and add the table
124142 table = Table (name = table_name , columns = columns , data = [])
125143 tables .add_table (table )
126-
144+
127145 print (f"\n ✓ Table '{ table_name } ' created successfully!" )
128146 print ("Columns:" )
129147 for col in columns :
130148 pk_indicator = " (PRIMARY KEY)" if col .is_primary_key else ""
131- default_indicator = f" (default: { col .default } )" if col .default is not None else ""
149+ default_indicator = (
150+ f" (default: { col .default } )" if col .default is not None else ""
151+ )
132152 print (f" - { col .name } : { col .type .value } { pk_indicator } { default_indicator } " )
133-
153+
134154 except KeyboardInterrupt :
135155 print ("\n \n Table creation cancelled." )
136156 except Exception as e :
@@ -139,7 +159,7 @@ def interactive_create_table(workdir: Path):
139159
140160def main ():
141161 parser = ArgumentParser (description = "Run SQL queries on JSON files." )
142-
162+
143163 # Add top-level arguments for backward compatibility
144164 parser .add_argument ("--code" , type = str , help = "SQL query to execute" , default = None )
145165 parser .add_argument (
@@ -161,13 +181,15 @@ def main():
161181 choices = ["json" , "csv" ],
162182 help = "Output format (default: json)" ,
163183 )
164-
184+
165185 # Add subcommands
166186 subparsers = parser .add_subparsers (dest = "command" , help = "Available commands" )
167-
187+
168188 # Query command
169189 query_parser = subparsers .add_parser ("query" , help = "Run SQL queries" )
170- query_parser .add_argument ("--code" , type = str , help = "SQL query to execute" , default = None )
190+ query_parser .add_argument (
191+ "--code" , type = str , help = "SQL query to execute" , default = None
192+ )
171193 query_parser .add_argument (
172194 "--workdir" ,
173195 type = Path ,
@@ -187,26 +209,26 @@ def main():
187209 choices = ["json" , "csv" ],
188210 help = "Output format (default: json)" ,
189211 )
190-
212+
191213 # Create table command
192214 create_parser = subparsers .add_parser ("create" , help = "Create database objects" )
193- create_subparsers = create_parser .add_subparsers (dest = "create_command" , help = "Create commands" )
194-
215+ create_subparsers = create_parser .add_subparsers (
216+ dest = "create_command" , help = "Create commands"
217+ )
218+
195219 table_parser = create_subparsers .add_parser ("table" , help = "Create a table" )
196220 table_parser .add_argument (
197- "--interactive" ,
198- action = "store_true" ,
199- help = "Create table interactively"
221+ "--interactive" , action = "store_true" , help = "Create table interactively"
200222 )
201223 table_parser .add_argument (
202224 "--workdir" ,
203225 type = Path ,
204226 default = Path .cwd (),
205227 help = "Directory to create the table in" ,
206228 )
207-
229+
208230 args = parser .parse_args ()
209-
231+
210232 # Handle commands
211233 if args .command == "create" and args .create_command == "table" :
212234 if args .interactive :
@@ -246,7 +268,9 @@ def main():
246268 else :
247269 print ("JSON SQL CLI" )
248270 print ("Type 'exit' to quit." )
249- print ("Tip: Use 'abstra-json-sql create table --interactive' to create tables." )
271+ print (
272+ "Tip: Use 'abstra-json-sql create table --interactive' to create tables."
273+ )
250274 while True :
251275 try :
252276 code = input ("> " )
0 commit comments