Welcome to longan-SQlite3 V0.8


We understand that you need a more convenient, efficient and lightweight tool to record data and spread the value of it to others. Longan-sqlite3 (Github address) is our answer ———— let you complete the following functions as you like

  • Create
  • Retrieve
  • Update
  • Delete

The longan-SQlite3 version you’re looking at is a development release only, with more features to come

0.8 fixed how to obtain the primary key of a table and added Kernel and FastFlesh to simplify operations

0.7 Adding Creating a Table

0.6 added sorting and pagination functions to support almost all aggregation functions

1. Add support for “between” and “in”. The init method provides the debug mode to print SQL statements

0.4 Added API documents

0.3 Added group aggregation function

0.2 fixed primary key judgment and handler interface


What is longan

Longan is a kind of fruit, very sweet, like people to eat a lot, don’t like people to eat on fire!

1. Here are the features we have planned

  • [x] support CRUD
  • [x] supports grouped aggregate functions
  • [x] Fix API documentation
  • [x] Added WHERE statement support

2. Here is our behavior conservation formula

longan = mc ** 2

3. Usage

  • Import the longan
from longan_sqlite import Longan, Flesh
Copy the code
  • Initialize the longan
Longan.init('test.db'.True)
Copy the code
  • Instantiation of longan
longan = Longan('company')
Copy the code
  • Import the database (this will be abstracted in a future release)
longan.execute_file('company.sql')
Copy the code
  • The table structure is company.sql
CREATE TABLE IF NOT EXISTS COMPANY(
   id INTEGER PRIMARY KEY AUTOINCREMENT,
   name           TEXT    NOT NULL,
   age            INT     NOT NULL,
   address        CHAR(50),
   salary         REAL
);
Copy the code
  • Create
flesh = Flesh(name='emperor', age=23, address='Beijing', salary=10)
longan.insert_or_update(flesh)
Copy the code
  • Update
flesh.age += 1
flesh.salary += 5
longan.insert_or_update(flesh)
Copy the code
  • Query
ret = longan.where(age_gt=18, salary_elt=100, salary_gt=0).query()
for r in ret:
    print(r)
Copy the code
  • Delete
# query
ret = longan.where(age_gt=18, salary_elt=100, salary_gt=0).query()

for r in ret:
    print(r)
    if r.name == 'jobs':
        Delete by object
        longan.delete(r)

Delete by condition
longan.where(id_gt=0).delete()
Copy the code
  • 0.3 Added Group Aggregation Query
longan.aggregate(age_max="maxAge", salary_min="minSalary")
longan.where(age_gt=5)
longan.group_by('address')
ret = longan.query()
for r in ret:
    print(r)
Copy the code

4. The API documentation

interface parameter instructions
init db_path, debug After the database file is initialized and the debug mode is enabled, SQL statements are printed
select Not open. The current version defaults to selecting all fields unless an aggregate function is used
from_table table_name Specify the query table
where **field_condition Taking a page from Django’s query operations, the “_” is preceded by the field name and followed by the expression, passing the value
insert_or_update *field_obj Inserting or updating one or more Flesh objects into the table automatically adds a primary key to the object
delete *field_obj You can use the WHERE method to delete based on conditions, or you can delete one or more Flesh objects directly if they have a primary key
group_by field Groups the specified field
aggregate **field_condition See where statement: field name _ aggregate function name =” alias”
query Query, need to use in combination
primary_key A primary key
ignore_case ignore Whether to ignore case
limit num, offset paging
order_by field, desc Sort by field