Package: icecoal
IcecoalIcecoal is a light weight SQL databaseTargets are,Apps that require SQL DB or external DB serverApps that need lightweight replacement for oracle, MySQL etc.., which they use just to store and retrieve dataThose who want to add a database in their app without worrying about any technical jargons such as JDBC, ODBC, Connection driver etc..Those who want to conveniently process CSV files with SQL.Features:Written purely in pythonLight weight (Just 57 Kb in total)No external dependenciesEasy to add in your app/system (Just import!)How to installpip install icecoalUsageGeneral database operationsfromicecoalimportqueryquery("select name,age from travel_db/passengers where native='USA'")Examplefromicecoalimportquerydefdisplay_names():display_query="""selectname, agefromstudent_db/courseswheremark>50"""result=query(display_query)ifresult[0]==0:forrowinresult[2]:print("Name is "+row[0]+" and Age is "+row[1])else:print(result[1])display_names()Processing your csv data filesfromicecoalimportqueryquery("select * from path/to/passengers.csv where native='USA'")Here icecoal expects first line of csv file to be header line.if it is not, you can either add headers in first lineor create a new file just with headers delimited with comma and add it along with data file name in the query as belowfromicecoalimportqueryquery("select * from path/to/passengers.csv, path/to/header.csv where native='USA'")Examplefromicecoalimportquerydefdisplay_names():display_query="""selectpricefromD://reports/sales.csv, D://reports/header.csvwherestore='online'"""result=query(display_query)ifresult[0]==0:forrowinresult[2]:print("Price : "+row[0])else:print(result[1])display_names()Change delimiters other than commaThis feature is to expand users ability to process files that are delimited with chatacters other than comma.fromicecoalimportsetdel,querysetdel("\t")query("select * from path/to/datafile.xyz")setdel()function will make further calls to query function to interpret data file as custom delimited (which is given bysetdel()parameter)Get current default delimiterfromicecoalimportgetdelgetdel()getdel()function will return current delimiter which is used to process data files.Return format[sqlcode,'<message>',[result list]]SQL return codesSQL CodeDescription20 row(s) deleted30 row(s) updated10 row(s) selected0Success-1Query incomplete-2Unexpected character on position <index>-3Unexpected character on where clause position <index>-4Unsupported operator in where clause-5Non numeric operand with arithmatic operator <operator>-6Non boolean operand(LHS) with logical operator <operator>-7Non boolean operand(RHS) with logical operator <operator>-8Operator ! must be followed by =-9Unbalanced paranthesis on LHS of operator <operator>-10Unbalanced paranthesis on RHS of operator <operator>-11No field <fieldname> found in header file-12Value for variable <variablename> is missing in atleast one row-13Where clause condition returns non-boolean result-14Incomplete condition in where clause-15Database already exist-16Table already exist-17Database does not exist-18Database name is blank-19Not a database name-20Table does not exist-21Not a table name-22Header file does not exist-23Provided header is not a file-24Values count does not match table fields countReserved wordsKeywordsSELECTFROMWHERECREATEDATABASETABLEINSERTUPDATESETINTOTRUNCATEDROPDELETESupported SQL operations and its syntaxSELECTcolumn_listFROM [path/to/]databasename/tablename[.csv] [WHEREcondition]CREATE DATABASE [path/to/]databasenameCREATE TABLE [path/to/]databasename/tablename[.csv](colum1,column2..)DROP DATABASE [path/to/]databasenameDROP TABLE [path/to/]databasename/tablename[.csv]TRUNCATE TABLE [path/to/]databasename/tablename[.csv]INSERT INTO [path/to/]databasename/tablename[.csv](value1,value2,..)UPDATE [path/to/]databasename/tablename[.csv] SETfield1=value1,field2=value..[WHEREcondition]DELETE FROM [path/to/]databasename/tablename[.csv] WHEREconditionCharacter escape',",\,#shoule be escaped with\inside a string as\',\",\\,\#icecoal has an inbuilt functionescape()for this. you can call this function as follows.fromicecoalimportescapeescaped_string=escape("your string goes here")Operators supportedOperator typeOperatorsArithmatic operators+, -, *, /, %Comparison operators>, <, >=, <=, =, !=Logical operators&, |End of query statement# (Used internally)Operator precedence (in order from high to low)NOTE :Expression evaluation will use BODMAS as you studied in school. i.e., It has individual operator precedence unlike python or java.Example :'9-7+1' will result '1'(That's how we were taught in school), where python eval() will return 3 as it treats + and - with equal precedence from left to rightYou can use paranthesis to re-order precedenceOperator precedence%/*+-<,<=>,>=!==&|File formats supportedComma seperated value(.csv) files by default.Can be extended to support any files withsetdel()function. for example to process tab seperated files, usesetdel("\t")before executingquery("...")InstructionsTables are referred with '/' character from database like 'db/table'String values should be within ''Comparison operator '=' is used instead of '=='Database,table names can contain only alphabet, number and underscoreField names can contain only alphabets,number and underscoreAll the exceptions are thrown to be handled by usersBy default icecoal stores all its databases in current directory unless you prefix path with tablenameLicenceMIT Licence. Please raise a pull request to contribute.