Sueta
SQ

SQLSimpleAPI

0.4

Make SQL simple

·Plugin

SQLSimpleAPI

For server administrator:
Just install the .jar in your plugin folder, there is nothing to configure

For developpers:
This API allow you to design class container (by using annotations) for data you want to store. You can then send the container through the DatabaseUtils of you choice (sqlite or MySQL)

It currently support the following SQL types :

  1. TEXT
  2. INTEGER
  3. DOUBLE
  4. VARCHAR
  5. BLOB (only MySQL)

Also supporting data length, PRIMARY KEY, NOT NULL and AUTO_INCREMENT

Here is a basic container definition :

@Row(tableName = "dbTable")
    public static class DataContainer extends Request
    {
        @Value(fieldName = "value1", type = DataType.INTEGER)
        public int value;
  
        @Value(fieldName = "value2", type = DataType.TEXT)
        public String text;
  
        /*
         * Where clause is used when retrieving data from the db
         * Here id is a VARCHAR(15)
         * You can set multiple Where clauses in a row, they will be added together to make a AND statement
        */
        @Where(fieldName = "id", type = DataType.VARCHAR)
        @Value(fieldName = "id", type = DataType.VARCHAR, infos = {KeyInfo.PRIMARY_KEY}, length = 15)
        public String id;
  
        @Override
        public void postInsert(DatabaseUtils utils) throws WrongBaseClassException, DataRetrieveException {}

        @Override
        public void postUpdate(DatabaseUtils utils) throws WrongBaseClassException, DataRetrieveException {}

        @Override
        public void postRetrieve(DatabaseUtils utils) throws WrongBaseClassException, DataRetrieveException {}
    }

And here is how you send it to the database :

public static void insertData() throws WrongBaseClassException, TableCreationException, DataInsertionException
    {
        DataContainer container = new DataContainer();
        container.value = 12;
        container.text = "myText";
        container.id = "container1";
        dbUtils.insertData(container);
    }
 
    public static void retrieveData() throws WrongBaseClassException, DataRetrieveException
    {
        DataContainer retriever = new DataContainer();
        retriever.id = "container1";
        retriever = dbUtils.retrieveData(retriever);
    }
 
    public static void deleteData() throws WrongBaseClassException, DataDeleteException
    {
        DataContainer deleter = new DataContainer();
        deleter.id = "container1";
        dbUtils.deleteData(deleter);
    }
 
    public static void main(String[] args) throws ConnectionException, WrongBaseClassException, TableCreationException, DataInsertionException, DataRetrieveException, DataDeleteException
    {
        dbUtils.connect();
        dbUtils.createTable(DataContainer.class);
        insertData();
        retrieveData();
        deleteData();
        dbUtils.close();
    }

You can find other usage example here -> https://gitlab.com/AtomixSoldier/SQLSimpleAPI/snippets
Also support database update, more SQL type support will come

Please report any bug in the comment section, I'm also open to any suggestion
You can also refer to the gitlab issues tracking -> https://gitlab.com/AtomixSoldier/SQLSimpleAPI/issues/

Similar projects

Plugin →