Utility for using mssql-tools BCP command with Django models
Project description
# django-sql-server-bcp
A utility for using mssql-tools BCP command with Django models.
#Installation
`pip install django-sql-server-bcp`
#Usage
Example Django model:
```python
from django.db import models
class StockPrice(models.Model):
id = models.AutoField(primary_key=True)
symbol = models.CharField(max_length=50)
price = models.DecimalField(max_digits=15, decimal_places=4)
timestamp = models.DateTimeField()
```
**Example BCP usage with `StockPrice` Model.**
Create a dict with the properties of your model. Then save via BCP:
```python
from random import radom
rows = []
for i in range(1, row_count):
rows.append(dict(
symbol='GOOG',
price='%.2f' % (100 * random()),
timestamp=str(datetime.datetime.now())
))
bcp = BCP(StockPrice)
bcp.save(rows)
print cp.save(rows)
```
You should output similar to the following:
```
Starting copy...
499 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 10 Average : (49900.0 rows per sec.)
```
#Caveats
- String data cannot contain commas or newlines because bulk data file format is flimsy CSV.
- Untested with long strings, dates, binary data.
A utility for using mssql-tools BCP command with Django models.
#Installation
`pip install django-sql-server-bcp`
#Usage
Example Django model:
```python
from django.db import models
class StockPrice(models.Model):
id = models.AutoField(primary_key=True)
symbol = models.CharField(max_length=50)
price = models.DecimalField(max_digits=15, decimal_places=4)
timestamp = models.DateTimeField()
```
**Example BCP usage with `StockPrice` Model.**
Create a dict with the properties of your model. Then save via BCP:
```python
from random import radom
rows = []
for i in range(1, row_count):
rows.append(dict(
symbol='GOOG',
price='%.2f' % (100 * random()),
timestamp=str(datetime.datetime.now())
))
bcp = BCP(StockPrice)
bcp.save(rows)
print cp.save(rows)
```
You should output similar to the following:
```
Starting copy...
499 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 10 Average : (49900.0 rows per sec.)
```
#Caveats
- String data cannot contain commas or newlines because bulk data file format is flimsy CSV.
- Untested with long strings, dates, binary data.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-sql-server-bcp-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ced119c41c60c68a81921c05e50a58b548c6fca1e3b56bb228e8a3258570ecc1 |
|
MD5 | bd37a4733e091dd87ca64078088722f9 |
|
BLAKE2b-256 | 495f39c91a69fcb6bc3572d13f59325d799f947581da698dbe3b34a9f212cbe3 |