Skip to content
/ csvrm Public

Python CSV Relation Mapping

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt
Notifications You must be signed in to change notification settings

mcimam/csvrm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSV RM

DO NOT USE ON PRODUCTION

Object relational mapping from csv file. This module will load csv to memory and treat it like Object. This module main purpose is to ease up csv usage in small application, mainly in use in sandboxing. It's highly ineficient and doesn't support multiple instance.

Features

CSV RM provide basic orm utility such as :

  • Load cscv to object
  • Create new record
  • Update existing record
  • Delete records
  • Search records

What not supported yet:

  • Transaction
  • Concurrent usage

Installation

Just install it directly using pip. No dependecies needed.

pip install csvrm

Or you can just copy entire source code.

Usage

  1. Define model structure Defining new model by inheriting Model class. Put csv file location inside _filename variable. Define each fields you want to extract by specifiy it as object.
from csvrm import models, fields

class Person(models.Model):
    _filename = '[filepath]'

    id = fields.Integer()
    name = fields.String()
  1. Create records
p = Person(load = true)
p.create({
    'id': 1,
    'name': 'person name'
})
p.save()
  1. Seach records
p = Person(load = true)
result = p.search(lambda x: x.name == 'person name')
for res in result:
    print(res.name)
  1. Update records Updating record can be done using either update methods or directly change properties
p = Person(load = true)

result = p.search(lambda x: x.name == 'person name')
for res in result:
    res.name = 'new person name'
p.save()

# OR
p.update(
    domain=(lambda x: x.id == 10),
    values= {'name': 'new person name'}
)
p.save()
  1. Delete records
p = Person(load = true)
p.unlink(
    domain=(lambda x: x.id == 10)
)
p.save()

FOR FULL DETAIL, READ THE CODE

Contributing

Fell free to port or contribute this project

About

Python CSV Relation Mapping

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages