All Projects → kamac → Askxml

kamac / Askxml

Licence: mit
Run SQL statements on XML documents

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Askxml

Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (+41.77%)
Mutual labels:  xml, sql, query
Hashover Next
This branch will be HashOver 2.0
Stars: ✭ 353 (+346.84%)
Mutual labels:  xml, sql
Loukoum
A simple SQL Query Builder
Stars: ✭ 305 (+286.08%)
Mutual labels:  sql, query
Qone
Next-generation web query language, extend .NET LINQ for javascript.
Stars: ✭ 463 (+486.08%)
Mutual labels:  sql, query
Roapi
Create full-fledged APIs for static datasets without writing a single line of code.
Stars: ✭ 253 (+220.25%)
Mutual labels:  sql, query
Sq
swiss-army knife for data
Stars: ✭ 275 (+248.1%)
Mutual labels:  xml, sql
Walkable
A Clojure(script) SQL library for building APIs: Datomic® (GraphQL-ish) pull syntax, data driven configuration, dynamic filtering with relations in mind
Stars: ✭ 384 (+386.08%)
Mutual labels:  sql, query
Sqliterally
Lightweight SQL query builder
Stars: ✭ 231 (+192.41%)
Mutual labels:  sql, query
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+860.76%)
Mutual labels:  xml, query
Fluentpdo
A PHP SQL query builder using PDO
Stars: ✭ 783 (+891.14%)
Mutual labels:  sql, query
Node Jl Sql Api
SQL for JS objects streams
Stars: ✭ 19 (-75.95%)
Mutual labels:  sql, query
Il Ilce Mahalle Sokak Cadde Sql
Türkiye İl, İlçe, Mahalle, Sokak, Cadde Bilgisi SQL Şeklinde
Stars: ✭ 235 (+197.47%)
Mutual labels:  xml, sql
Bancosbrasileiros
Lista de bancos brasileiros | Brazilian banks list
Stars: ✭ 178 (+125.32%)
Mutual labels:  xml, sql
Preql
An interpreted relational query language that compiles to SQL.
Stars: ✭ 257 (+225.32%)
Mutual labels:  sql, query
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (+1330.38%)
Mutual labels:  xml, sql
Baby squeel
🐷 An expressive query DSL for Active Record 4 and 5
Stars: ✭ 362 (+358.23%)
Mutual labels:  sql, query
Bigbash
A converter that generates a bash one-liner from an SQL Select query (no DB necessary)
Stars: ✭ 230 (+191.14%)
Mutual labels:  sql, query
Termsql
Convert text from a file or from stdin into SQL table and query it instantly. Uses sqlite as backend. The idea is to make SQL into a tool on the command line or in scripts.
Stars: ✭ 230 (+191.14%)
Mutual labels:  sql, query
Poco
The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
Stars: ✭ 5,762 (+7193.67%)
Mutual labels:  xml, sql
Pypika
PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
Stars: ✭ 1,111 (+1306.33%)
Mutual labels:  sql, query

AskXML

Run SQL statements on XML documents

<xml>
    <fruit color='green'>tasty kiwi</fruit>
    <fruit color='dark green'>old kiwi</fruit>
    <fruit color='green'>apple</fruit>
</xml>
>>> from askxml import AskXML

>>> conn = AskXML('file.xml')
# get an SQL cursor object
>>> c = conn.cursor()
>>> results = c.execute("SELECT color FROM fruit WHERE _text LIKE '% kiwi'")
>>> for row in results.fetchall():
>>>    print(row)
[('green'), ('dark green')]

# cleanup
>>> c.close()
>>> conn.close()

BUT WHY?

There are data dumps like stack exchange's, stored in XML. They're big, so fitting them whole into memory is not desired. With AskXML you can query things fast, and rather comfortably (provided you know SQL).

Before you go any further though, it's very possible your task can be achieved with XPATH and ElementTree XML API, so give that a look if you haven't heard of it.

Installation

AskXML requires Python 3.5+. Best way to install is to get it with pip:

pip install askxml

Usage

Adding indexes and defining columns

If you want to add indexes, columns or set attribute types, you can pass a list of table definitions:

from askxml import *
tables = [
    Table('fruit',
        Column('age', Integer()),
        Index('age'))
]
with AskXML('file.xml', table_definitions=tables) as conn:
    c = conn.cursor()
    c.execute("UPDATE fruit SET age = 5 WHERE _text = 'tasty kiwi'")
    c.close()

You don't need to define all existing columns or tables. If a definition was not found, it's created with all column types being Text by default.

Node hierarchy

If you want to find nodes that are children of another node by attribute:

<xml>
    <someParent name='Jerry'>
        <someChild name='Morty' />
        <someChild name='Summer' />
    </someParent>
</xml>
from askxml import *
with AskXML('file.xml') as conn:
    c = conn.cursor()
    results = c.execute("""
        SELECT name FROM someParent_someChild as child
        INNER JOIN someParent as parent ON parent._id = child._parentId
        WHERE parent.name = 'Jerry'
    """)
    for row in results.fetchall():
        print(row)
    c.close()

This will print [('Morty'), ('Summer')].

Inserting new data

If you want to add a new tag:

cursor.execute("INSERT INTO fruit (color, _text) VALUES ('red', 'strawberry')")

Or if your nodes have a hierarchy:

cursor.execute("INSERT INTO someParent_someChild (name, _parentId) VALUES ('a baby', 1)")

Contributing

Any contributions are welcome.

License

AskXML is licensed under MIT license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].