Skip to main content

No project description provided

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csvrm-0.2.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file csvrm-0.2.tar.gz.

File metadata

  • Download URL: csvrm-0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.0

File hashes

Hashes for csvrm-0.2.tar.gz
Algorithm Hash digest
SHA256 7498072efd215ed86d56755c2719547bc6be8e150dd066c29b0bf5f77b5c3e77
MD5 5b427097fcb22b2c8f640f691568f468
BLAKE2b-256 2bac91a39c302709ac8cbb38fee23bf3e2eb834a48fe64973a3302e5123f699e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page